Question link: Click the open link
It is a bitwise operation function that asks how many steps can be taken to obtain a given number;
Train of Thought: I am not opportunistic to create a table, but I can only create a table... The thought of table creation is to use a set of available numbers to represent the State BFs. In the end, there is a need for 11 steps, which requires nearly 1 H. Except this 10 minute is enough.
CPP:
# Include <cstdio> # include <cstring> # include <queue> # include <vector> # include <map> using namespace STD; int mark [300]; struct node {int deep; vector <int> us; void Init () {deep = 0; us. push_back (15); US. push_back (51); US. push_back (85); US. push_back (0); US. push_back (255);} bool find (int n) {for (INT I = 0; I <us. size (); I ++) if (US [I] = N) return 1; return 0 ;}}; int NAND (int A, int B) {return (255 ^ (A & B) ;}queue <node> q; Map <VEC Tor <int>, bool> map; // The checkbool check () {int bj = 1; for (INT I = 0; I <256; I ++) {If (MARK [I] <0) {bj = 0 ;}} if (bj) for (INT I = 0; I <256; I ++) {printf ("% d,", Mark [I]);} return BJ;} // leave the last check version bool check () {int CNT = 0; for (INT I = 0; I <256; I ++) {If (MARK [I] <0) {CNT ++ ;}} if (CNT <2) for (INT I = 0; I <256; I ++) {printf ("% d,", Mark [I]);} return (CNT <2 );} void BFS () {node TPE; TPE. init (); q. push (TPE); For (INT I = 0; I <5; I ++) {mark [TPE. Us [I] = 0;} while (! Check () {node TP = Q. front (); q. pop (); For (INT I = 0; I <TP. us. size (); I ++) {for (Int J = 0; j <TP. us. size (); j ++) {int temp = NAND (TP. us [I], TP. us [J]); If (MARK [temp] <0) MARK [temp] = TP. deep + 1; if (! TP. find (temp) {node He = TP; he. deep ++; he. us. push_back (temp); sort (HE. us. begin (), he. us. end (); If (Map [He. us] = 1) continue; Map [He. us] = 1; q. push (HE) ;}}}} int main () {for (INT I = 0; I <256; I ++) MARK [I] =-1; BFS (); Return 0 ;}
HDU 5077 NAND (table) 2014 Asia Regional Anshan Station H