10pts求调 悬关
查看原帖
10pts求调 悬关
921114
_ImposterX_楼主2023/7/10 20:31
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m;
char ch[105][105];
bool vis[105][105];
bool dis[105][105];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
queue<pair<ll,ll> > q;
bool bfs(int x,int y){
	q.push(make_pair(x,y));
	vis[x][y]=1;
	while(q.size()){
		x=q.front().first;
		y=q.front().second;
		q.pop();
		if(x<1||x>n||y<1||y>m) continue;
		vis[x][y]=1;
		//cout<<x<<' '<<y<<endl;
		if(x==n&&y==m) return true;
		for(int i=0;i<4;i++){
			int xx=x+dx[i];
			int yy=y+dy[i];
			if(dis[xx][yy]&&vis[xx][yy]==0){
				q.push(make_pair(xx,yy));
			}
		}
	}
	if(x==n&&y==m) return true;
	return false;
} 
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>ch[i][j],dis[i][j]=(ch[i][j]=='.');
	
	if(bfs(1,1)) puts("Yes");
	else puts("No");
	return 0;
}
2023/7/10 20:31
加载中...