40pts求调
查看原帖
40pts求调
1241536
hong__hua__miao楼主2025/8/4 16:48
#include <bits/stdc++.h>
using namespace std;
int dx[5] = {0,0,0,1,-1};
int dy[5] = {0,1,-1,0,0};
const int N = 105;
int a[N][N];
bool vis[N][N];
int n,m;
bool flag;
void dfs(int now_x,int now_y){
	if (now_x == n && now_y == m){
		flag = 1;
		return ;
	}
	if (flag == 1)
		return ;
	for (int i = 1; i <= 4; ++i){
		int xx = now_x + dx[i],yy = now_y + dy[i];
		if (xx >= 1 && xx <= n && yy >= 1 && yy <= m && a[xx][yy] && !vis[xx][yy]){
			vis[xx][yy] = 1;
			dfs(xx,yy);
		}
	}
}
int main(){
	std::ios::sync_with_stdio(false);
	cout.tie(0);cin.tie(0);
	scanf("%d%d",&n,&m);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j){
			char c;
			cin >> c;
			a[i][j] = (c == '.');
		}
	dfs(1,1);
	vis[1][1];
	if (flag) printf("Yes");
	else printf("No");
	return 0;
}
2025/8/4 16:48
加载中...