Topic links
http://acm.hdu.edu.cn/showproblem.php?pid=1253
Wide Search Questions
1#include <stdio.h>2#include <string.h>3#include <queue>4#include <algorithm>5 #defineINF 0X6FFFFFF6 #defineN 557 using namespacestd;8 9 intMaps[n][n][n],vis[n][n][n];Ten One intdir[6][3]={ {0,0,1},{0,1,0},{1,0,0},{0,0,-1},{0,-1,0},{-1,0,0} }; A - inta,b,c,t; - the structnode - { - intX,y,z,step; - }; + - BOOLJudgeintXintYintz) + { A returnx<a&&x>=0&&y<b&&y>=0&&z<c&&z>=0&&maps[x][y][z]==0&&vis[x][y][z]==0; at } - - intBFS (node S,node e) - { -Queue<node>Q; - node q; inmemset (Vis,0,sizeof(Vis)); -vis[s.x][s.y][s.z]=1; to Q.push (s); + while(!q.empty ()) - { theq=Q.front (); * Q.pop (); $ if(Q.x==e.x&&q.y==e.y&&q.z==e.z && Q.step <=t)Panax Notoginseng returnQ.step; - the if(Q.step >t) + return-1; A the for(intI=0;i<6; i++) + { -s.x=q.x+dir[i][0]; $s.y=q.y+dir[i][1]; $s.z=q.z+dir[i][2]; - if(judge (S.x, S.y, s.z)) - { thevis[s.x][s.y][s.z]=1; -s.step=q.step+1;Wuyi Q.push (s); the } - } Wu } - return-1; About $ } - - intMain () - { A intT,i,j,k,ans; + node s,e; thescanf"%d",&T); - while(t--) $ { thememset (Maps,0,sizeof(maps)); the thescanf"%d %d%d%d",&a,&b,&c,&t); the for(i=0; i<a;i++) - { in for(j=0; j<b;j++) the { the for(k=0; k<c;k++) About { thescanf"%d",&maps[i][j][k]); the } the } + } -s.x=s.y=s.z=s.step=0; thee.x=a-1; e.y=b-1; e.z=c-1;Bayi theans=BFS (s,e); the - if(a+b+c-3>t) -ans=-1; theprintf"%d\n", ans); the } the return 0; the}
Victory Grand Escape--hdu1253