P1746求助
查看原帖
P1746求助
566249
kkkscp03楼主2022/5/14 15:14

自家电脑上能过,但在洛谷上编译失败

#include<bits/stdc++.h>
using namespace std;
struct node{
	int a,b;
};
char mapp[1005][1005];
int cnt[1005][1005];
int x1,x2,y1,y2,n;
int dx[4]={1,0,-1,0};
int dy[4]={0,-1,0,1};
void bfs(int x,int y){
	queue<node> q;
	node s={x,y};
	q.push(s);
	while(q.empty()==false){
		node head=q.front();
		if(head.a==x2&&head.b==y2){
			return;
		}
		for(int i=0;i<4;i++){
			int tx=head.a+dx[i];
			int ty=head.b+dy[i];
			if(mapp[tx][ty]=='0'&&cnt[tx][ty]==0){
				q.push({tx,ty});
				cnt[tx][ty]=cnt[head.a][head.b]+1;
			}
		}
		q.pop();
	}
}
int main(){
	for(int i=0;i<1005;i++){
		for(int j=0;j<1005;j++){
			mapp[i][j]='1';
		}
	}
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>mapp[i][j];
		}
	}
	cin>>x1>>y1>>x2>>y2;
	bfs(x1,y1);
	cout<<cnt[x2][y2];
	return 0;
}
2022/5/14 15:14
加载中...