#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
struct node {
int x;
int y;
int k;
}b;
queue<node> q;
int n, m, y11, x1, y2, x2, f;
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
int vis[110][110];
char map[110][110];
void bfs()
{
while (!q.empty())
{
q.pop();
}
vis[x1][y11] = 1;
q.push({ x1,y11,-1 });
while (!q.empty())
{
node a;
a = q.front();
q.pop();
if (a.x == x2 && a.y == y2 && a.k <= f)
{
cout << "yes" << endl;
return;
}
b.k = a.k + 1;
for (int i = 0; i < 4; i++)
{
int nx = a.x + dx[i];
int ny = a.y + dy[i];
while (nx >= 0 && nx < n && ny >= 0 && ny < m && map[nx][ny] != '*')
{
if (!vis[nx][ny])
{
vis[nx][ny] = 1;
b.x = nx; b.y = ny;
q.push(b);
}
nx = nx + dx[i];
ny = ny + dy[i];
}
}
}
cout << "no" << endl;
}
int main()
{
int T;
cin >> T;
while (T--) {
cin >> n >> m;
memset(vis, 0, sizeof(vis));
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
cin >> map[i][j];
}
cin >> f >> y11 >> x1 >> y2 >> x2;
y2 = y2 - 1; x1 = x1 - 1;
x2 = x2 - 1; y11 = y11 - 1;
bfs();
}
return 0;
}//s
不只 周围的四个加入队列 而是从这个点 向上下左右所有不为障碍物的点加入队列
for (int i = 0; i < 4; i++)
{
int nx = a.x + dx[i];
int ny = a.y + dy[i];
while (nx >= 0 && nx < n && ny >= 0 && ny < m && map[nx][ny] != '*')
{
if (!vis[nx][ny])
{
vis[nx][ny] = 1;
b.x = nx; b.y = ny;
q.push(b);
}
nx = nx + dx[i];
ny = ny + dy[i];
}
}