求调
  • 板块灌水区
  • 楼主Charlie_Nine
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/10/7 11:01
  • 上次更新2024/10/7 12:50:58
查看原帖
求调
1349424
Charlie_Nine楼主2024/10/7 11:01
#include<bits/stdc++.h>
using namespace std;
int h,w;
int dx[4]={-1,0,0,1};
int dy[4]={0,-1,1,0};
struct xy{
	int x,y;
};
char dt[510][510];
char ddd(char a){
	switch(a){
		case 's':{
			return 'n';
		}
		case 'n':{
			return 'u';
		}
		case 'u':{
			return 'k';
		}
		case 'k':{
			return 'e';
		}
		case 'e':{
			return 's';
		}
	}
}
bool f[510][510];
bool BFS(){
	xy fxy;
	fxy.x=1;
	fxy.y=1;
	queue<xy> q;
	q.push(fxy);
	while(!q.empty()){
		xy t=q.front();
		q.pop();
		if(t.x==h&&t.y==w){
			return 1;
		}
		for(int i=1;i<=4;i++){
			xy nt;
			nt.x=t.x+dx[i];
			nt.y=t.y+dy[i];
			if(f[nt.x][nt.y]!=1&&dt[nt.x][nt.y]==ddd(dt[t.x][t.y])){
				q.push(nt);
				f[nt.x][nt.y]=1;
			}
		}
	}
	return 0;
}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>h>>w;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>dt[i][j];
		}
	}
	if(BFS()==1)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}

本地无法输出结果

2024/10/7 11:01
加载中...