题解
2026-08-06 22:32:51
发布于:广东
5阅读
0回复
0点赞
c++
#include <iostream>
#include <cstring>
using namespace std;
int n, m, sx, sy, fx, fy, vis[1010][1010], nx[4] = {0,0,1,-1}, ny[4] = {1,-1,0,0};
char a[1010][1010];
void dfs(int x, int y) {
vis[x][y] = 1;
for (int i = 0; i < 4; i++) {
int xx = x + nx[i], yy = y + ny[i];
if (xx >= 1 && xx <= n && yy >= 1 && yy <= m && vis[xx][yy] == -1 && a[xx][yy] != '#') dfs(xx,yy);
}
}
int main () {
memset(vis, -1, sizeof vis);
scanf("%d %d\n%d %d %d %d\n", &n, &m, &sx, &sy, &fx, &fy);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
scanf("%c", &a[i][j]);
}
scanf("\n");
}
dfs(sx,sy);
if (vis[fx][fy] != -1) cout << "YES";
else cout << "NO";
return 0;
}
这里空空如也







有帮助,赞一个