迷宮問題
time limit:1000ms
memory limit:65536k
total submissions:31616
accepted:18100
定義乙個二維陣列:
int maze[5][5] = ;
它表示乙個迷宮,其中的1表示牆壁,0表示可以走的路,只能橫著走或豎著走,不能斜著走,要求程式設計序找出從左上角到右下角的最短路線。
乙個5 × 5的二維陣列,表示乙個迷宮。資料保證有唯一解。
左上角到右下角的最短路徑,格式如樣例所示。
sample input
0 1 0 0 0sample output0 1 0 1 0
0 0 0 0 0
0 1 1 1 0
0 0 0 1 0
(0, 0)source(1, 0)
(2, 0)
(2, 1)
(2, 2)
(2, 3)
(2, 4)
(3, 4)
(4, 4)
1.簡單dfs
#include#include#include#include#include#include#include#include#define n 100010using namespace std;
void in(int &x)
while(isdigit(c))
x*=f;
}int a[6][6],tot;
struct nodee[30],ans[30];
int mx[4]=,
my[4]=;
bool vis[6][6];
void print(int k)
void dfs(int x,int y,int tim)
}} int main()
2.簡單bfs(考慮如何更新)
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表示可以走的路,只能橫著走或豎著走,...