迷宮問題
題目鏈結 :
time limit:1000msmemory limit:65536kb64bit io format:%i64d & %i64u
定義乙個二維陣列:
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)
#include #include #include #include #include #include #include #include using namespace std;
struct a
w[5000];
int n=5,e=1;
int a[6][6],vis[6][6];
int cc[4][2]=;
queueq;
int bfs()
for(int i=0;i<4;i++)
while(!st.empty())
return 0;
}
POJ 3984 迷宮問題(BFS 回溯路徑)
迷宮問題 time limit 1000ms memory limit 65536k total submissions 7862 accepted 4615 description 定義乙個二維陣列 int maze 5 5 它表示乙個迷宮,其中的1表示牆壁,0表示可以走的路,只能橫著走或豎著走,...
迷宮問題bfs
迷宮問題 採用佇列的廣度優先遍歷 bfs 思想是從乙個頂點v0開始,輻射狀地優先遍歷其周圍較廣的區域 找到的解為最優解 include define m 8 define n 8 define maxsize 1000 typedef struct box typedef struct qutype...
迷宮問題BFS
the code 資料結構迷宮.cpp 定義控制台應用程式的入口點。include stdafx.h include include include include define n 4 定義迷宮為4 4 using namespace std struct pot 為記錄路徑的rec準備,座標 x...