标签:des style blog http io ar color os sp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1240
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3549 Accepted Submission(s):
2354
1 #include <iostream> 2 #include <cstdio> 3 #include <queue> 4 5 using namespace std; 6 7 int dir[6][3]={0,0,1,0,0,-1,0,1,0,0,-1,0,1,0,0,-1,0,0}; 8 char Map[25][25][25]; 9 int sx,sy,sz,ex,ey,ez,N,flag,step; 10 struct node{ 11 int x,y,z,t; 12 }s,ss; 13 14 void bfs() 15 { 16 queue<node>q,qq; 17 s.x=sx; 18 s.y=sy; 19 s.z=sz; 20 s.t=0; 21 q.push(s); 22 if (sx==ex&&sy==ey&&sz==ez) 23 { 24 flag=1; 25 step=0; 26 return ; 27 } 28 while (!q.empty()) 29 { 30 s=q.front(); 31 q.pop(); 32 //cout<<"1"<<endl; 33 for (int i=0;i<6;i++) 34 { 35 int x=s.x+dir[i][0]; 36 int y=s.y+dir[i][1]; 37 int z=s.z+dir[i][2]; 38 if (x>=0&&x<N&&y>=0&&y<N&&z>=0&&z<N&&Map[z][y][x]!=‘X‘) 39 { 40 ss.x=x; 41 ss.y=y; 42 ss.z=z; 43 ss.t=s.t+1; 44 Map[z][y][x]=‘X‘; 45 if (x==ex&&y==ey&&z==ez) 46 { 47 flag=1; 48 step=ss.t; 49 return ; 50 } 51 q.push(ss); 52 } 53 } 54 } 55 } 56 57 58 int main () 59 { 60 char str[15],ch[15]; 61 62 while (scanf("%s%d",str,&N)!=EOF) 63 { 64 //flag=0; 65 for (int i=0;i<N;i++) 66 for (int j=0;j<N;j++) 67 scanf("%s",Map[i][j]); 68 scanf("%d%d%d",&sx,&sy,&sz); 69 scanf("%d%d%d",&ex,&ey,&ez); 70 scanf("%s",ch); 71 flag=0; 72 bfs(); 73 if (flag==1) 74 printf ("%d %d\n",N,step); 75 else 76 printf ("NO ROUTE\n"); 77 } 78 return 0; 79 }
标签:des style blog http io ar color os sp
原文地址:http://www.cnblogs.com/qq-star/p/4149278.html