1211
1#include <cstdio>2#include <queue>3#include <cstring>4 using namespacestd;5 intSx,sy,ex,ey;6 intd[4][2]={1,0,0,1,-1,0,0,-1};7 BOOLvisit[9][9];8 9 intg[9][9]=Ten { One 1,1,1,1,1,1,1,1,1, A 1,0,0,1,0,0,1,0,1, - 1,0,0,1,1,0,0,0,1, - 1,0,1,0,1,1,0,1,1, the 1,0,0,0,0,1,0,0,1, - 1,1,0,1,0,1,0,0,1, - 1,1,0,1,0,1,0,0,1, - 1,1,0,1,0,0,0,0,1, + 1,1,1,1,1,1,1,1,1, - }; + A struct Point at { - intx; - inty; - intStep; - }; - in intBFS () - { to Point init; +init.x=SX; -init.y=Sy; theinit.step=0; *Queue<point>Q; $ Q.push (init);Panax Notoginseng while(!q.empty ()) - { thePoint node=Q.front (); + Q.pop (); A if(node.x==ex&&node.y==ey) the returnNode.step; + for(intI=0;i<4; i++) - { $ Point newnode; $newnode.x=node.x+d[i][0]; -newnode.y=node.y+d[i][1]; -newnode.step=node.step+1; the if(! g[newnode.x][newnode.y]&&Visit[newnode.x][newnode.y]) - Q.push (newnode);Wuyivisit[node.x][node.y]=false; the } - } Wu } - About intMain () $ { - //freopen ("In.txt", "R", stdin); - intT; -scanf"%d",&t); A while(t--) + { thememset (Visit,true,sizeof(visit)); -scanf"%d%d%d%d",&sx,&sy,&ex,&ey); $ intans=BFS (); theprintf"%d\n", ans); the } the return 0; the}