POJ 3984 迷宮問題

2021-10-03 12:04:07 字數 1439 閱讀 1044

題目鏈結

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)

具體思路

裸題的bfs迷宮路徑問題

#include

#include

#include

using

namespace std;

typedef

long

long

int lld;

lld changex[5]

=;lld changey[5]

=;lld maze[5]

[5];

lld times[5]

[5];

struct l

way[5]

[5];

void

ans(

) ansx[len]=0

; ansy[len]=0

;for

(lld i=

0;i<=times[4]

[4];i++

)return;}

intmain()

} times[0]

[0]=

0;queueduix;

queueduiy;

duix.

push(0

);duiy.

push(0

);way[0]

[0].perx=0;

way[0]

[0].pery=0;

while

(!duix.

empty()

&&!duiy.

empty()

)for

(lld i=

0;i<

4;i++)}

}return0;

}

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