40tps求调
查看原帖
40tps求调
1327857
Endless_summer楼主2024/7/17 11:53
#include<bits/stdc++.h>
#include<queue>
using namespace std;
struct node{int x,y;};
queue <node> Q;
const int mx[5]={0,1,-1,0, 0};
const int my[5]={0,0, 0,1,-1};
bool check[108][108]={};
char my_map[108][108];
int main(){
	int n,m,x,y;
	cin>>n>>m;
	check[1][1]=1;
	Q.push({1,1});
	for(int i=1; i<=n; i++) 
		for(int j=1; j<=m; j++) cin>>my_map[i][j];
	while(!Q.empty()){
		Q.pop();
		for(int i=1; i<=4; i++){
			x=Q.front().x+mx[i];
			y=Q.front().x+my[i];
			if(x>=1&&y>=1&&x<=n&&y<=m&&my_map[x][y]=='.') {
				if(!check[x][y]) Q.push({x,y});
				check[x][y]=1;
				if(x==n&&y==m) {
					printf("Yes");
					return 0;
				}
			}
		}
	}
	printf("No");
	return 0;
}
2024/7/17 11:53
加载中...