與其他bfs不同的是這種題需要用二進位制來儲存鑰匙這個狀態,需要多用一維陣列來儲存。。
可以通過位運算 | 「拾取鑰匙」, & 「匹配鑰匙」。
#include "string"
#include "iostream"
#include "cstdio"
#include "cmath"
#include "set"
#include "queue"
#include "vector"
#include "cctype"
#include "sstream"
#include "cstdlib"
#include "cstring"
#include "stack"
//#include "ctime"
#include "algorithm"
#define pa pair#define pi m_pi
#define inf 0x3f3f3f3f
#define infl 0x3f3f3f3f3f3f3f3fll
using namespace std;
typedef long long ll;
const int m=55;
struct node
star;
int n, m, time;
int dis[4][2] = ;
char map[21][21];
bool mark[20][20][1100];
int bfs()
if( map[node.x][node.y] == '^')
return node.t;
for( i = 0 ; i < 4 ; i++)
else if( isupper( map[next.x][next.y]) )
mark[next.x][next.y][next.kind] = true;
q.push(next);}}
return -1;
}int main()}}
ans = bfs();
printf("%d\n", ans);
}}
hdu 1429 勝利大逃亡 續 BFS狀壓
題目連線 題意 迷宮的加強版,迷宮裡有鑰匙和門,問在指定的時間下能否逃出 題解 用二進位制位來記錄是否有該門的鑰匙,然後上bfs include include include define ffc i,a,b for int i a i b i using namespace std int n,...
HDU1429 勝利大逃亡 狀壓bfs
因為總共a j有10種鑰匙,所以可以把有沒有鑰匙的狀態壓到乙個int數里,然後dfs。昨天狀態特別不好寫超時了好幾次,但是這個題很簡單的,算是水題。1 include2 include3 include4 include5 include6 include7 using namespace std ...
HDU1429 勝利大逃亡 續
學習位壓縮很好的一道題,因為只有10把鑰匙,那麼可以把10鑰匙壓縮二進位制,比如1000就表示身上只要第4把鑰匙的狀態,110表示帶有第2把和第3把鑰匙,那麼要判斷當前的鑰匙串有沒有能開啟當前門鑰匙,那麼就只要乙個 運算就可以,因為11101110 00100000 00100000 這樣就說明那一...