http://47.96.116.66/problem.php?cid=1177&pid=2
http://47.96.116.66/problem.php?cid=1180&pid=2
题解:BFS
/*
*@Author: STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=2000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
int ans,cnt,flag,temp,sum;
int a[N],b[N];
bool vis[N][N];
char str;
struct node{
int x,y,time;
}s,f,tmp;
int dir[4][2]={1,0,0,1,-1,0,0,-1};
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
//ios::sync_with_stdio(false);
//cin.tie(0);
//cout.tie(0);
//scanf("%d",&t);
//while(t--){
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
for(int i=1;i<=n;i++){
scanf("%d",&b[i]);
vis[a[i]+1000][b[i]+1000]=1;
}
// for(i=990;i<=1010;i++){
// for(j=990;j<=1010;j++){
// printf("%d%c",vis[i][j]," \n"[1010==j]);
// }
// }
queue<node>q;
s.x=1000;
s.y=1000;
s.time=0;
q.push(s);
vis[1000][1000]=1;
ans=1000;
while(!q.empty()){
f=q.front();
q.pop();
for(int i=0;i<4;i++){
tmp.x=f.x+dir[i][0];
tmp.y=f.y+dir[i][1];
tmp.time=f.time+1;
if(tmp.x<0||tmp.x>2000||tmp.y<0||tmp.y>2000)
continue;
if(vis[tmp.x][tmp.y])
continue;
if(tmp.time>k)
continue;
ans=max(tmp.x,ans);
//if(t++<20)
//cout<<tmp.x-1000<<" "<<tmp.y-1000<<" "<<abs(1000-tmp.x)+abs(1000-tmp.y)<<endl;
vis[tmp.x][tmp.y]=1;
q.push(tmp);
}
}
cout<<ans-1000<<endl;
//}
#ifdef DEBUG
printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
//cout << "Hello world!" << endl;
return 0;
}