救救孩子吧 玄关
查看原帖
救救孩子吧 玄关
1036002
yjjh楼主2024/7/3 17:15

WA两点 RE一点 awa

#include <bits/stdc++.h>
using namespace std;
const int N=1002;
int dt[N][N],n,x2,y2;
int xx[4]={1,0,-1,0};
int yy[4]={0,1,0,-1};
int q[100000000][3];
int tt=0,rr=1;
inline int bbfs(int x,int y,int bs){
	for(int i=0;i<4;i++){
		if(x+xx[i]>=1&&x+xx[i]<=n&&y+yy[i]>=1&&y+yy[i]<=n&&dt[x+xx[i]][y+yy[i]]==0){
			rr++;
			if(x+xx[i]==x2&&y+yy[i]==y2)return bs+1;
			q[rr][0]=x+xx[i],q[rr][1]=y+yy[i],q[rr][2]=bs+1,dt[x+xx[i]][y+yy[i]]=1;
		}
	}
	return 0;
}
inline int bfs(){
	while(rr>=tt){
		int t=bbfs(q[tt][0],q[tt][1],q[tt][2]);
		if(t)return t;
		tt++;
	}
}
int main(){
	std::cin >>n;
	for(int i=0;i<n;i++){
		string str;
		std::cin >>str;
		for(int j=0;j<n;j++){
			dt[i][j]=str[j]-'0';
		}
	}
	int x,y;
	std::cin >>x>>y>>x2>>y2;
	q[0][0]=x,q[0][1]=y;
	
	std::cout <<bfs();
	return 0;
}
2024/7/3 17:15
加载中...