社区讨论

90wa求调

B3625迷宫寻路参与者 2已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@m6acues6
此快照首次捕获于
2025/01/24 14:02
去年
此快照最后确认于
2025/01/24 16:45
去年
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;
char a[105][105];
bool vis[105][105];
int n,m;
struct str{
	int x,y;
};
int dx[]={1,1,0,-1};
int dy[]={-1,0,1,1};
bool bfs(){
	queue<str>q;
	q.push({1,1});
	while(!q.empty()){
		str ret=q.front();
		q.pop();
		if(ret.x==n&&ret.y==m){
			return true;
		}
		else{
			for(int i=0;i<4;i++){
				int nx=ret.x+dx[i];
				int ny=ret.y+dy[i];
				if(nx>=1&&ny>=1&&nx<=n&&ny<=m&&!vis[nx][ny]&&a[nx][ny]!='#'){
					vis[nx][ny]=1;
					q.push({nx,ny});
				}
			}
		}
	}
	return false;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	if(a[1][1]=='#'){
		cout<<"No";
	}
	else if(bfs()==1){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}

回复

2 条回复,欢迎继续交流。

正在加载回复...