poj 3984 迷宮問題

2021-07-04 09:22:33 字數 1154 閱讀 1679

迷宮問題

time limit:1000ms

memory limit:65536k

total submissions:11254

accepted:6731

description

定義乙個二維陣列:

int maze[5][5] = ;

它表示乙個迷宮,其中的1表示牆壁,0表示可以走的路,只能橫著走或豎著走,不能斜著走,要求程式設計序找出從左上角到右下角的最短路線。

input

乙個5 × 5的二維陣列,表示乙個迷宮。資料保證有唯一解。

output

左上角到右下角的最短路徑,格式如樣例所示。

sample input

0 1 0 0 0

0 1 0 1 0

0 0 0 0 0

0 1 1 1 0

0 0 0 1 0

sample output

(0, 0)

(1, 0)

(2, 0)

(2, 1)

(2, 2)

(2, 3)

(2, 4)

(3, 4)

(4, 4)

嗯,這題和之前做的不一樣,之前都是求最小步數,這個要列印出路徑,不會。。。
然後見人家討論區里開了個陣列存之前的點的位置,行乘以5再加上列數
#include#include#includeusing namespace std;

int map[8][8],mark[8][8];

int rec[30];

int dir[4][2]=;

struct node

;int judge(int x,int y)

void print()

for(int j=i;j>=0;j--) }

void bfs(int x,int y)

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

} }}

int main()

bfs(0,0);

return 0;

}

POJ3984 迷宮問題

題目 迷宮問題 time limit 1000ms memory limit 65536k total submissions 3183 accepted 1861 description 定義乙個二維陣列 int maze 5 5 它表示乙個迷宮,其中的1表示牆壁,0表示可以走的路,只能橫著走或豎...

POJ 3984 迷宮問題

一道比較簡單的bfs題 include include include include define max 6 using namespace std int map max max px max max py max max int movex 4 movey 4 bool vis max ma...

POJ 3984 迷宮問題

迷宮問題 time limit 1000ms memory limit 65536k total submissions 7047 accepted 4123 description 定義乙個二維陣列 int maze 5 5 它表示乙個迷宮,其中的1表示牆壁,0表示可以走的路,只能橫著走或豎著走,...