求助。。本地没问题提交全re 莫名其妙
查看原帖
求助。。本地没问题提交全re 莫名其妙
21852
囧雪诺楼主2020/5/20 18:28
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
using namespace std;
struct wz{
	int x,y,bu;
}s;
wz add(int x,int y,int b){
	wz p;
	p.x=x;
	p.y=y;
	p.bu=b;
	return p;
}
int main(){
	int n,x1,x2,y1,y2,ans;
	cin>>n;
	int a[n+5][n+5]={1};
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++) a[i][j]=getchar()-'0';
		getchar();
	}
	
	cin>>x1>>y1>>x2>>y2;
	queue<wz> q;
	s.x=x1;
	s.y=y1;
	s.bu=0;
	q.push(s);
	while(!q.empty()){
		wz t1=q.front();
		if(t1.x==x2&&t1.y==y2){
			ans=t1.bu;break;
		}
		if(a[t1.x][t1.y]!=1){
			q.push(add(t1.x+1,t1.y,t1.bu+1));
			q.push(add(t1.x,t1.y+1,t1.bu+1));
			q.push(add(t1.x-1,t1.y,t1.bu+1));
			q.push(add(t1.x,t1.y-1,t1.bu+1));
		}
		q.pop();
	}
	cout<<ans;
}
2020/5/20 18:28
加载中...