Very simple search questions, write casually.
Topic links
1#include <stdio.h>2#include <string.h>3 intSt;4 Chars[Ten];5 intq[70000],vis[70000],front,tail;6 Const intdx[]={1,-1,0,0};7 Const intdy[]={0,0,1,-1};8 intBFS () {9Front=tail=0;Tenmemset (vis,-1,sizeof(Vis)); Oneq[tail++]=St; Avis[st]=0; - while(front!=tail) { - intu=q[front++]; the if(!u| | u==65535) - returnVis[u]; - for(intx=0;x<4; x + +) - for(inty=0;y<4; y++) { + intv=u; -v^=1<< (x<<2)+y); + for(intj=0;j<4; j + +) { A intnx=x+dx[j],ny=y+Dy[j]; at if(0<=nx&&nx<4&&0<=ny&&ny<4) { -v^=1<< (nx<<2)+NY); - } - } - if(vis[v]==-1) { -vis[v]=vis[u]+1; inq[tail++]=v; - } to } + } - return-1; the } * $ intMain () {Panax Notoginseng while(~SCANF ("%s", s)) { -st=0; the for(intI=0;i<4; i++) +st=st<<1| (s[i]=='b'); A for(intj=0;j<3; j + +) { thescanf"%s", s); + for(intI=0;i<4; i++) -st=st<<1| (s[i]=='b'); $ } $ intans=BFS (); - if(ans==-1) -Puts"Impossible"); the Else -printf"%d\n", ans);Wuyi } the return 0; -}
View Code
POJ 1753 Flip Game simple BFS