[ 提交][
狀態][
討論版][命題人:
如圖所示,迷宮的入口為(1,1),出口為(8,8)。用佇列求迷宮
樣例輸出
1 12 1
3 14 1
5 15 2
5 36 3
6 46 5
7 58 5
8 68 7
8 8在看了老師提供的題解後,感覺用指標寫會十分麻煩而且感覺比較亂,就用自己的思路重新做了一下這道題。
感覺**中還有很多地方可以優化,有些地方寫的也不是很清楚,若有人找到希望能給予指#include#include#include#includeusing namespace std;
int map[50][50]=,,,
,,,,
,,};int n[4][2]=,,,};
struct px[50][50];
stacko;//用於調整輸出格式
queueque;
int dx,dy,i,v[50][50];
p k,l;
void bfs(int a,int b)
else if(v[dx][dy]==0&&map[dx][dy]==0)
} }}int main()
printf("1 1\n");
while(!o.empty())
return 0;
}
用BFS解決迷宮問題
在乙個n n的矩陣裡走,從原點 0,0 開始走到終點 n 1,n 1 僅僅能上下左右4個方向走。僅僅能在給定的矩陣裡走,求最短步數。n n是01矩陣,0代表該格仔沒有障礙。為1表示有障礙物。int mazearr maxn maxn 表示的是01矩陣 int steparr 4 2 表示上下左右4個...
迷宮問題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...