' . ' 才是空地
2024-03-24 08:41:00
发布于:黑龙江
21阅读
0回复
0点赞
#include <iostream>
using namespace std;
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int n, m, fx, fy, sx, sy;
const int N = 10;
char a[N][N];
bool st[N][N];
int cnt = 0;
bool flag;
void dfs(int x, int y)
{
if (x == fx && y == fy){
flag = true;
return ;
}
st[x][y] = true;
for (int i = 0; i < 4; i ++){
int nx = x + dx[i];
int ny = y + dy[i];
if (nx <= 0 || ny <= 0 || nx > n || ny > m)continue;
if (!st[nx][ny] && a[nx][ny] == '.'){
// st[nx][ny] = true;
dfs(nx, ny);
// st[nx][ny] = false;
}
}
}
int main()
{
cin >> n >> m ;
cin >> sx >> sy >> fx >> fy;
for (int i = 1; i <= n; i ++){
for (int j = 1; j <= m; j ++){
cin >> a[i][j];
}
}
st[sx][sy] = true;
dfs(sx, sy);
if (flag)cout << "YES";
else cout << "NO";
return 0;
}
这里空空如也
有帮助,赞一个