RE求助
查看原帖
RE求助
1011303
YR123楼主2023/10/2 12:57

求助为何RE

#include<bits/stdc++.h>
using namespace std;
int n,sx,sy,ex,ey,ans;
char c[1005][1005];
int fx[]={0,0,1,-1};
int fy[]={1,-1,0,0};
struct Node{
	int x,y,cnt;
};
int bfs(){
	c[sx][sy]='1';
	queue<Node>q;
	q.push({sx,sy,0});
	while(!q.empty()){
		Node h=q.front();
		q.pop();
		if(h.x==ex&&h.y==ey) return h.cnt;
		for(int i=0;i<4;i++){
			int tx=h.x+fx[i];
			int ty=h.y+fy[i];
			if(tx>=1&&tx<=n&&ty>=1&&ty<=n&&c[tx][ty]=='0'){
				q.push({tx,ty,h.cnt+1});
				c[tx][ty]='1';
			}
		}
	}
	return -1;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			c[i][j]=getchar();
		}
		getchar();
	}
	cin>>sx>>sy>>ex>>ey;
	cout<<bfs();
	return 0;
}

2023/10/2 12:57
加载中...