HDU 1253 勝利大逃亡

2022-07-31 08:45:10 字數 739 閱讀 3203

用dfs會超時,而且bfs不剪枝的話也會超時。。。三維搜尋。。。

搜尋題,三維bfs,設定前後上下左右6個方向搜尋

1.剛開始一直wa,我就一直找不出錯誤,後來在看這個題時才發現自己犯了個嚴重的錯誤,剛開我就把城堡四周賦值為1,後來就沒這樣初始化了;現在想想吧太不應該了;

2、要認清剪枝的重要性,剪枝非常有利於提高**的效率,就這題而言,若沒有if(a+b+c-3>t) (起點與終點間最短路徑大於時間限度),雖然沒超時;

#include

<

stdio.h

>

#include

<

stdlib.h

>

struct

node

t[200024

];int

dis[6][

3]=,,,,, };

intmap[

54][

54][

54],n,m,h;

intbfs(

intx,

inty,

intz,

inttime )

if( map[dx][dy][dz]==0

)

}first

++;

} return-1

;

}int

main( )

}return

0;

}

hdu 1253 勝利大逃亡

先前在次處漏掉了,could come的判斷,結果一直wa。if step t could come include include struct q 150000 int head,tail,step,add step flag int input 52 52 52 int end x,end y...

HDU 1253 勝利大逃亡

這個題比較坑的bfs吧,注意如果判邊界的話可能會超時,最好先人為加邊界,然後進行搜尋,搜尋最好是隊尾判斷,因為可能出現起點和終點相同的資料 wa了很久 include include includeusing namespace std const int maxn 52 struct node q...

HDU 1253 勝利大逃亡

ignatius被魔王抓走了,有一天魔王出差去了,這可是ignatius逃亡的好機會.魔王住在乙個城堡裡,城堡是乙個a b c的立方體,可以被表示成a個b c的矩陣,剛開始ignatius被關在 0,0,0 的位置,離開城堡的門在 a 1,b 1,c 1 的位置,現在知道魔王將在t分鐘後回到城堡,i...