用递归求解
/*********************************************************************
程序名:
日期: 2026-05-16 16:44
说明:
*********************************************************************/
#include <bits/stdc++.h>
using namespace std;
char a[103][103];//地图
bool v[103][103];// 标记
int k, n, s1, s2, e1, e2, f;
int fx[] = {-1, 1, 0, 0};
int fy[] = {0, 0, -1, 1};
void dfs(int x, int y) {
v[x][y] = 1;
if (————?——) {
f = ?__;
return ;
}
// x-1,y x+1,y x,y-1 x,y+1
// if(x-1>=1 && x-1<=n && y>=1 &&y<=n && v[x-1][y]==0 && a[x-1][y]!='#' && f==0) dfs(x-1,y);
for (int i = 0; i <= 3; i++) {
int tx = x + fx[i];
int ty = y + fy[i];
if (__?_)
dfs(__?_);
}
return ;
}
int main() {
cin >> k;
for (int t = 1; t <= k; t++) {
// 每组测试数据
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
v[i][j] = 0;
}
}
cin >> s1 >> s2 >> e1 >> e2;
s1++;
s2++;
e1++;
e2++;
if (a[s1][s2] == '#' || a[e1][e2] == '#') {
cout << "NO\n";
continue;
}
// s1,s2;
f = 0;
dfs(s1, s2);
if (f == 1) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
return 0;
}