90wa求调
查看原帖
90wa求调
1264576
2010zhuanghaojun楼主2025/1/24 14:00
#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";
	}
}
2025/1/24 14:00
加载中...