#define _CRT_SECURE_NO_DEPRECATE
#include
#include
#include
#include
using namespace std;
#define size 110
struct node
{
int h,l;
int wi;
};
node b;
char map[size][size];
int dir[4][2] = { 0, 1, -1, 0, 0, -1, 1, 0 }, visit[size][size];
int m, n, k;
int bfs(node a,int l)
{
if (map[b.h][b.l] == '*') return 0;
if (a.h == b.h&&a.l == b.l) return 1; //在函数头加判断条件
queue
q; int j; node a1; q.push(a); while (1) { l++; if (l > k) return 0; a=q.front(); while (a.wi==l-1) { for (j = 0; j < 4; j++) { a1.h = dir[j][0] + a.h; a1.l = dir[j][1] + a.l; a1.wi = l; while (1<=a1.h&&a1.h<=n&&1<=a1.l&&a1.l<=m&&map[a1.h][a1.l] == '.'&&visit[a1.h][a1.l]>=l) { //直接判断比建墙法便捷一些 if (a1.h == b.h&&a1.l == b.l) return 1; q.push(a1); visit[a1.h][a1.l] = l; a1.h += dir[j][0]; a1.l += dir[j][1]; a1.wi = l; } } q.pop(); if (q.empty()) return 0; else a = q.front(); } } } int main(void) { int t; node a; scanf("%d", &t); while (t--) { int i, j; scanf("%d %d", &n, &m); for (i = 1; i <= n; i++) { scanf("%s", map[i]+1); for(j = 0; j <= m + 1; j++) visit[i][j] = 100; } //迷宫的基本特征的刻画 scanf("%d %d %d %d %d", &k, &a.l, &a.h, &b.l, &b.h); a.wi = -1; visit[a.h][a.l] = -1; if (bfs(a, -1)) printf("yes\n"); else printf("no\n"); } return 0; } /* 44 9 13 ..**********. ..*.......... ..*.*******.. ..*.*..*..*.. ..*.*****.*.. ..*.......*.. ..*********.. ............. ............. 6 1 1 9 4 3 3 ... *** ... 11 1 1 3 3 1 1 * 1 1 1 1 1 */
hdu 逃离迷宫
最新推荐文章于 2021-03-16 15:52:53 发布