逃離迷宮 HDU 1728

2021-08-18 19:25:19 字數 1831 閱讀 2125

hdu - 1728

給定乙個m × n (m行, n列)的迷宮,迷宮中有兩個位置,gloria想從迷宮的乙個位置走到另外乙個位置,當然迷宮中有些地方是空地,gloria可以穿越,有些地方是障礙,她必須繞行,從迷宮的乙個位置,只能走到與它相鄰的4個位置中,當然在行走過程中,gloria不能走到迷宮外面去。令人頭痛的是,gloria是個沒什麼方向感的人,因此,她在行走過程中,不能轉太多彎了,否則她會暈倒的。我們假定給定的兩個位置都是空地,初始時,gloria所面向的方向未定,她可以選擇4個方向的任何乙個出發,而不算成一次轉彎。gloria能從乙個位置走到另外乙個位置嗎?

input  第1行為乙個整數t (1 ≤ t ≤ 100),表示測試資料的個數,接下來為t組測試資料,每組測試資料中, 

第1行為兩個整數m, n (1 ≤ m, n ≤ 100),分別表示迷宮的行數和列數,接下來m行,每行包括n個字元,其中字元'.'表示該位置為空地,字元'*'表示該位置為障礙,輸入資料中只有這兩種字元,每組測試資料的最後一行為5個整數k, x 1, y 1, x 2, y 2 (1 ≤ k ≤ 10, 1 ≤ x1, x 2 ≤ n, 1 ≤ y 1, y 2 ≤ m),其中k表示gloria最多能轉的彎數,(x 1, y 1), (x 2, y2)表示兩個位置,其中x 1,x 2對應列,y 1, y 2對應行。 

output  每組測試資料對應為一行,若gloria能從乙個位置走到另外乙個位置,輸出「yes」,否則輸出「no」。sample input

2

5 5...**

*.**.

.....

.....

*....

1 1 1 1 3

5 5...**

*.**.

.....

.....

*....

2 1 1 1 3

sample output

no

yes

題解+解析:

#include #include#include#include#include #include #include #include #define inf 0x7f7f7f7f

typedef long long ll;

using namespace std;

int w, h;

int n;

int sx, sy, gx,gy;

char map[105][105];

int m[4][2] = ;

struct node

};bool flag;

bool visit[105][105];

int c;

void bfs(int x, int y, int k)

queueque;

visit[x][y] = 1;

que.push(node(x,y,k,0));//壓入該初始方向的第乙個node

while (que.size())

;struct node

};void bfs()

queueque;

que.push(node(sx,sy,0));

vis[sx][sy] = true;

for(int i = 0 ; i < 4; ++i)

if(!vis[nx][ny])

nx+=dir[i][0], ny+=dir[i][1];

if(0<=nx&&nxcontinue;

else

break;}}

}}

}int main()

return 0;

}

hdu 1728 逃離迷宮

思路 一開始我是往左和往右走,不轉彎,計數不用加,往上和往下走,就轉彎,計數就加一,進行廣搜,搜到最後那個點,比較就可以啦,但是華麗麗的wa啦。所以改一條路搜到底,走不了啦,就一定要轉彎啦。include include include includeusing namespace std stru...

HDU 1728 逃離迷宮

bfs 搞清楚是轉彎而不是步數。所以需要乙個方向一直走下去直到邊界或者牆。還有就是注意題意。給出起點終點的 x,y 位置是交換的。題目是下標1開始。注意。include include include include include include include include include i...

HDU 1728 逃離迷宮

逃離迷宮 time limit 1000msmemory limit 32768kb64bit io format i64d i64u submit status description 給定乙個m n m行,n列 的迷宮,迷宮中有兩個位置,gloria想從迷宮的乙個位置走到另外乙個位置,當然迷宮中...