迷宫
https://www.acwing.com/problem/content/1114/
#include<bits/stdc++.h>
using namespace std;
const int N = 150;
char g[N][N];
bool st[N][N];
int n;
int sx, sy, ex, ey;
int dx[] = { -1, 1, 0, 0 }, dy[] = { 0, 0, -1, 1 };
void dfs(int x,int y)
{
st[x][y] = true;
bool success = false;
for (int i = 0; i < 4; i++)
{
int nx = x + dx[i], ny = y + dy[i];
if (nx >= 1 && nx <= n&&ny >= 1 && ny <= n&&st[nx][ny] == false&&g[nx][ny]=='.')
{
success = true;
dfs(nx, ny);
}
}
if (!success) return;
}
int main()
{
int t;
cin >> t;
while (t--)
{
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
cin >> g[i][j];
}
}
cin >> sx >> sy >> ex >> ey;
sx++, sy++, ex++, ey++;
memset(st, false, sizeof st);
dfs(sx,sy);
if (g[sx][sy] == '#' || g[ex][ey] == '#') puts("NO");
else
{
if (st[ex][ey]) puts("YES");
else puts("NO");
}
}
return 0;
}