求大佬帮忙看看为什么全RE
查看原帖
求大佬帮忙看看为什么全RE
380214
dreammer_mu楼主2021/3/31 14:37
#include <iostream>
#include <queue>
#define MAXN 1000
using namespace std;
int map[MAXN][MAXN];
int vis[MAXN][MAXN];
int sx[4]={1,-1,0,0};
int sy[4]={0,0,1,-1};
struct node{
	int x,y,step;
}t1,t2;
queue <node> q;
void bfs(int a,int b,int c,int d,int n){
	t1.x=a;t1.y=b,t1.step=0;
	q.push(t1);
	while(!q.empty()){
		t1=q.front();
		q.pop();
		if(t1.x==c && t1.y==d){
			cout<<t1.step<<endl;
			return;
		}
		for(int i=0;i<4;i++){
			t2.x=t1.x+sx[i];t2.y=t1.y+sy[i];t2.step=t1.step+1;
			vis[t2.x][t2.y]=1;
			q.push(t2);
			if( map[t2.x][t2.y] == 1 || t2.x>n ||t2.x<=0||t2.y>n ||t2.y<=0 || vis[t2.x][t2.y]==1){
				continue;
				}
		}
	}	
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>map[i][j];
		}
	}
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	bfs(a,b,c,d,n);
	return 0;
}

脑袋要炸了,谢谢各位大佬

2021/3/31 14:37
加载中...