63 lines
1.4 KiB
C++
63 lines
1.4 KiB
C++
#include <bits/stdc++.h>
|
||
using namespace std;
|
||
struct Node {
|
||
int x;
|
||
int y;
|
||
int step;
|
||
};
|
||
const int N = 110;
|
||
int dx[] = {-1, 0, 1, 0};
|
||
int dy[] = {0, 1, 0, -1};
|
||
char g[N][N];
|
||
bool st[N][N];
|
||
int n;
|
||
int xa, ya, xb, yb; // 不能使用x1,y1这样的变量名,可能是万能头中有重复声明
|
||
bool flag;
|
||
void bfs() {
|
||
flag = false;
|
||
if (g[xa][ya] == '#') return;
|
||
if (g[xb][yb] == '#') return;
|
||
memset(st, 0, sizeof st);
|
||
|
||
if (xa == xb && ya == yb) {
|
||
flag = true;
|
||
return;
|
||
}
|
||
|
||
queue<Node> q;
|
||
q.push({xa, ya, 0});
|
||
st[xa][ya] = true;
|
||
|
||
while (q.size()) {
|
||
auto t = q.front();
|
||
q.pop();
|
||
for (int i = 0; i < 4; i++) {
|
||
int x = t.x + dx[i], y = t.y + dy[i];
|
||
if (x < 0 || x >= n || y < 0 || y >= n) continue;
|
||
if (st[x][y]) continue;
|
||
if (g[x][y] == '#') continue;
|
||
if (x == xb && y == yb) {
|
||
flag = true;
|
||
return;
|
||
}
|
||
q.push({x, y, t.step + 1});
|
||
st[x][y] = true;
|
||
}
|
||
}
|
||
}
|
||
int main() {
|
||
int T;
|
||
cin >> T;
|
||
while (T--) {
|
||
cin >> n;
|
||
for (int i = 0; i < n; i++) cin >> g[i];
|
||
|
||
cin >> xa >> ya >> xb >> yb;
|
||
bfs();
|
||
if (flag)
|
||
cout << "YES" << endl;
|
||
else
|
||
cout << "NO" << endl;
|
||
}
|
||
return 0;
|
||
} |