http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=473
没什么意思
View Code
1 #include <iostream> 2 #include<cstdio> 3 #include<string.h> 4 using namespace std; 5 char s[31][31][31]; 6 struct node 7 { 8 int x,y,z,num; 9 }q[100001]; 10 int d,p,n,m,o,f[31][31][31],re[7][3] = {{0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0}}; 11 void inque(int x,int y,int z) 12 { 13 d++; 14 q[d].x = x; 15 q[d].y = y; 16 q[d].z = z; 17 } 18 int judge(int x,int y,int z) 19 { 20 if(x<1||x>n||y<1||y>m||z<1||z>o) 21 return 0; 22 if(f[x][y][z]) 23 return 0; 24 if(s[x][y][z]=='#') 25 return 0; 26 return 1; 27 } 28 int main() 29 { 30 int i,j,k,a[5]; 31 while(scanf("%d%d%d",&n,&m,&o)!=EOF) 32 { 33 memset(f,0,sizeof(f)); 34 if(n==0&&m==0&&o==0) 35 break; 36 for(i = 1; i <= n ; i++) 37 { 38 getchar(); 39 for(j = 1 ; j <= m ; j++) 40 { 41 for(k = 1; k <= o ; k++) 42 { 43 s[i][j][k] = getchar(); 44 if(s[i][j][k]=='S') 45 { 46 a[1] = i; 47 a[2] = j; 48 a[3] = k; 49 } 50 } 51 getchar(); 52 } 53 } 54 d = 1; 55 p = 0; 56 q[d].x = a[1]; 57 q[d].y = a[2]; 58 q[d].z = a[3]; 59 q[d].num = 0; 60 int flag = 0; 61 while(p!=d) 62 { 63 p++; 64 int tx = q[p].x; 65 int ty = q[p].y; 66 int tz = q[p].z; 67 int tnum = q[p].num; 68 if(s[tx][ty][tz]=='E') 69 { 70 flag = 1; 71 break; 72 } 73 for(i = 0; i < 6 ; i++) 74 { 75 int px = tx+re[i][0]; 76 int py = ty+re[i][1]; 77 int pz = tz+re[i][2]; 78 if(judge(px,py,pz)) 79 { 80 f[px][py][pz] = 1; 81 inque(px,py,pz); 82 q[d].num = q[p].num+1; 83 } 84 } 85 } 86 if(flag) 87 printf("Escaped in %d minute(s).\n",q[p].num); 88 else 89 printf("Trapped!\n"); 90 } 91 return 0; 92 }