【藍橋杯】迷宮(BFS+路徑記憶)

思想:簡單的BFS問題,在尋路的過程中,判斷四個方向時,優先判斷字典序小的方向,若滿足未訪問過就會優先加入隊列,最後找到的路,即爲字典序最小。 這裏我們在node節點中,引入變量s,用來記錄到這個節點時,所有的方向序列。 #include<iostream> #include<queue> using namespace std; struct node{ int x; int y; s
相關文章
相關標籤/搜索