HDU 1728 逃離迷宮

2021-07-10 21:36:11 字數 1810 閱讀 1336

逃離迷宮

time limit:1000msmemory limit:32768kb64bit io format:%i64d & %i64u

submit

status

description

給定乙個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 ≤ x 

1, x 

2 ≤ n, 1 ≤ y 

1, y 

2 ≤ m),其中k表示gloria最多能轉的彎數,(x 

1, y 

1), (x 

2, y 

2)表示兩個位置,其中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#includeusing namespace std;

const int maxn = 110;

char mapn[maxn][maxn];

int sig[maxn][maxn];

int m,n,flag;

int k,s_x,s_y,e_x,e_y;

int dir[4][2]=,,,};

struct nodes_pos;

bool cheak(int x,int y)

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

}else

}else}}

}}

}}int main()

bfs();

if(flag) cout<<"yes"

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 逃離迷宮

problem description 給定乙個m n m行,n列 的迷宮,迷宮中有兩個位置,gloria想從迷宮的乙個位置走到另外乙個位置,當然迷宮中有些地方是空地,gloria可以穿越,有些地方是障礙,她必須繞行,從迷宮的乙個位置,只能走到與它相鄰的4個位置中,當然在行走過程中,gloria不能...