样例通过,RE求助
查看原帖
样例通过,RE求助
436102
nod1212楼主2021/12/4 23:28
#include<bits/stdc++.h>
using namespace std;
struct pointt{
	int xg;
	int yg;
	int step;
};
bool ma[1002][1002]; 
int n;
queue<pointt> q;
bool ch(pointt tm){
	bool fla=ma[tm.xg][tm.yg]||tm.xg>n||tm.yg>n||tm.xg<1||tm.yg<1;
	return !fla;
}
int main(){
	cin>>n;
	getchar();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			char t=getchar();
			if(t=='0'){
				ma[i][j]=false;
			}
			else{
				ma[i][j]=true;
			}
		}
		getchar();
	}
	int xxx,yyy,xxs,yys;
	cin>>xxx>>yyy>>xxs>>yys;
	pointt a;
	a.xg=xxx;
	a.yg=yyy;
	a.step=0;
	q.push(a);
	while(1){
		if(q.front().xg==xxs&&q.front().yg==yys){
			cout<<q.front().step;
			return 0;
		}
		a=q.front();
		if(!ch(a)){
			q.pop();
			continue;
		}
		ma[a.xg][a.yg]=true;
		a.step++;
		q.pop();
		a.xg++;
		if(ch(a)){
			q.push(a);
		}
		a.xg-=2;
		if(ch(a)){
			q.push(a);
		}
		a.xg++;
		a.yg++;
		if(ch(a)){
			q.push(a);
		}
		a.yg-=2;
		if(ch(a)){
			q.push(a);
		}
	}
	return 0;
}
2021/12/4 23:28
加载中...