help 70pts(壶关)
查看原帖
help 70pts(壶关)
1047537
wuzhuoran楼主2024/12/8 17:40
#include<bits/stdc++.h>
using namespace std;

const int KD[10][2]={{-1,0},{1,0},{0,-1},{0,1}};
int n,m,a,b,l[250000][2],y,x,t,T[505][505],f[505][505];

int main(){
	cin>>n>>m>>a>>b;
	for(int i=1; i<=a; i++){
		cin>>x>>y;
		t++;
		l[t][0]=x;
		l[t][1]=y;
		f[x][y]=1;
	}
	for(int i=1; i<=t; i++){
		for(int j=0; j<4; j++){
			x=l[i][0]+KD[j][0];
			y=l[i][1]+KD[j][1];
			if(x>=1&&x<=n&&y>=1&&y<=m&&f[x][y]==0){
				if(f[x][y]==0){
				T[x][y]=T[l[i][0]][l[i][1]]+1;
				t++;
				l[t][0]=x;
				l[t][1]=y;
				f[x][y]=1;					
				}

			}
		}
	}
	for(int i=1; i<=b; i++){
		cin>>x>>y;
		cout<<T[x][y]<<endl;
	}
	return 0;
}
2024/12/8 17:40
加载中...