Direct violence wide search can be.
"The internet has great God said two-way wide search speed, but direct violence wide search can be over"
The state in the queue is stored in binary order.
I used a comparison of SB's wording, do not spray qaq
1#include <queue>2#include <cstdio>3 4 using namespacestd;5 6UnsignedintStart, End;7 BOOLm[4][4];8 9 Const intDx[] = {+0, +0, +1, -1};Ten Const intDy[] = {+1, -1, +0, +0}; One A voidInit () - { - Charmap[4][4]; theUnsignedintTemp; - for(inti =0; I! =4;++i) - { -scanf"%s", Map +i); +Temp =0; - for(intj =0; J! =4;++j) +(Temp <<=1) + = Map[i][j]-'0'; AStart + = (Temp << (i <<2)); at } - for(inti =0; I! =4;++i) - { -scanf"%s", Map +i); -Temp =0; - for(intj =0; J! =4;++j) in(Temp <<=1) + = Map[i][j]-'0'; -End + = (Temp << (i <<2)); to } + } - the intdist[100050]; * $ voidBFS ()Panax Notoginseng { -queue<unsignedint>Q; the Q.push (Start); +UnsignedintTop, Temp, Go; A intx, y; theDist[start] =1; + while(Q.size ()) - { $Top =Q.front (); $ Q.pop (); - for(inti =0; I! =4;++i) - for(intj =0; J! =4;++j) theM[I][J] = (Top & (1<< (i *4+ (3-J ))); - for(inti =0; I! =4;++i)Wuyi for(intj =0; J! =4;++j) the if(M[i][j]) - for(intK =0; K! =4;++k) Wu { -x = i + dx[k], y = j +Dy[k]; About if(x >=0&& x <4&& y >=0&& y <4) $ if(!M[x][y]) - { - swap (M[i][j], m[x][y]); -Go =0; A for(inti =0; I! =4;++i) + { theTemp =0; - for(intj =0; J! =4;++j) $(Temp <<=1) +=M[i][j]; theGo + = (Temp << (i <<2)); the } the if(!Dist[go]) the { -Dist[go] = Dist[top] +1; in Q.push (Go); the } the swap (M[i][j], m[x][y]); About } the } the if(Dist[end]) the Break; + } - } the Bayi intMain () the { the init (); - BFS (); -printf"%u", Dist[end]-1); the return 0; the}Bzoj 1054
Bzoj 1054 [HAOI2008] Mobile Toys