迷宮問題
time limit:1000ms
memory limit:65536k
total submissions:9718
accepted:5742
description
定義乙個二維陣列:
int maze[5][5] = ;
它表示乙個迷宮,其中的1表示牆壁,0表示可以走的路,只能橫著走或豎著走,不能斜著走,要求程式設計序找出從左上角到右下角的最短路線。
input
乙個5 × 5的二維陣列,表示乙個迷宮。資料保證有唯一解。
output
左上角到右下角的最短路徑,格式如樣例所示。
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)(1, 0)
(2, 0)
(2, 1)
(2, 2)
(2, 3)
(2, 4)
(3, 4)
(4, 4)
用dfs做的。。。
#includeint map[10][10];int book[10][10];
int tx,ty;
int next[4][2]=,,,};
bool isbound(int x,int y)
else }
void dfs(int x ,int y)
for(k=0;k<4;k++)
if(map[tx][ty]==0)
{ if(book[x][y]+1
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表示可以走的路,只能橫著走或豎著走,...