求找DEBUG
查看原帖
求找DEBUG
794484
huanglihuan楼主2024/5/9 21:04

永远输出 No:

#include <bits/stdc++.h>
#include <cstdio>
#define int long long
using namespace std;
const int N = 105;

int n,m;
char mp [N] [N];
bool vis [N] [N];

void dfs (int x,int y)
{
	if (x == n && y == m)
	{
		cout << "Yes";
		exit (0);
	}
	vis [x] [y] = true;
	if (x + 1 <= n && x + 1 >= 1 && mp [x + 1] [y] == '.' && ! vis [x + 1] [y]) dfs (x + 1,y);
	if (x - 1 <= n && x - 1 >= 1 && mp [x - 1] [y] == '.' && ! vis [x - 1] [y]) dfs (x - 1,y);
	if (y + 1 <= n && y + 1 >= 1 && mp [x] [y + 1] == '.' && ! vis [x] [y + 1]) dfs (x,y + 1);
	if (y - 1 <= n && y - 1 >= 1 && mp [x] [y - 1] == '.' && ! vis [x] [y - 1]) dfs (x,y - 1);
	cout << "No";
	exit (0);
}
signed main () {
	ios :: sync_with_stdio (false);
	cin.tie (0),cout.tie (0);
	cin >> n >> m;
	for (int i = 1;i <= n;i ++)
		for (int j = 1;j <= m;j ++) cin >> mp [i] [j];
	dfs (1,1);
	return 0;
}
2024/5/9 21:04
加载中...