poj3984 迷宮問題 輸出最短路徑BF

2021-06-22 09:21:06 字數 865 閱讀 8612

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)

# include

# include

int map[5][5];

int dir[4][2]=;  //可走的四個方向

struct node;

struct node queue[50],record[5][5];//queue記錄可走的點,廣搜;record記錄改點的前驅

void bfs() 

} } }}

int main()

for(i=k-1;i>=0;i--)//輸出路徑

printf("(%d, %d)\n",queue[i].x,queue[i].y);

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表示可以走的路,只能橫著走或豎著走,...