标签:ini cap nes blank ems roc for body you
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 50755 | Accepted: 19053 |
Description
Input
Output
Escaped in x minute(s).
Trapped!
Sample Input
3 4 5 S.... .###. .##.. ###.# ##### ##### ##.## ##... ##### ##### #.### ####E 1 3 3 S## #E# ### 0 0 0
Sample Output
Escaped in 11 minute(s). Trapped!
Source
1 #include<cstdio> 2 #include<iostream> 3 #include<queue> 4 #include<string> 5 #include<cstring> 6 #define sca(a) scanf("%d",&a ); 7 #define sca2(a,b) scanf("%d%d",&a,&b ); 8 #define sca3(a,b,c) scanf("%d%d%d",&a,&b,&c); 9 #define mem(a,b) memset(a,b,sizeof(a)); 10 #define FOR0(i,j) for(int i=0;i<=j;++i) 11 #define FOR1(i,j) for(int i=1;i<=j;++i) 12 using namespace std; 13 struct node 14 { 15 int x,y,z,step; 16 }; 17 char plat[40][40][40]; 18 int vis[40][40][40]; 19 int dir[6][3]={0,0,1,0,1,0,1,0,0,-1,0,0,0,-1,0,0,0,-1}; 20 int m,n,o; 21 int sx,sy,sz; 22 void ini() 23 { 24 mem(plat,0); 25 mem(vis,0); 26 } 27 int main() 28 { 29 //cout<<sx<<sy<<sz; 30 while(scanf("%d%d%d",&o,&m,&n)&&m+n+o) 31 { 32 ini(); 33 for(int i=1;i<=o;i++) 34 { 35 for(int j=1;j<=m;j++) 36 { 37 scanf("%s", plat[i][j]+1); 38 for(int k=1;k<=n;k++) 39 { 40 if(plat[i][j][k]==‘S‘) 41 { 42 sx=j;sy=k;sz=i; 43 } 44 } 45 } 46 } 47 //cout<<sx<<sy<<sz; 48 queue<node>q; 49 q.push({sx,sy,sz,0}); 50 vis[sz][sx][sy]=1; 51 int flag=0; 52 while(!q.empty()) 53 { 54 node now=q.front(); 55 q.pop(); 56 if(plat[now.z][now.x][now.y]==‘E‘) 57 { 58 flag=1; 59 printf("Escaped in %d minute(s).\n", now.step); 60 break; 61 } 62 int nex,ney,nez; 63 for(int i=0;i<6;i++) 64 { 65 nex=now.x+dir[i][0]; 66 ney=now.y+dir[i][1]; 67 nez=now.z+dir[i][2]; 68 if(nex<1||nex>m||ney<1||ney>n||nez<1||nez>o) continue; 69 if(vis[nez][nex][ney]) continue; 70 if(plat[nez][nex][ney]==‘.‘||plat[nez][nex][ney]==‘E‘) 71 { 72 //printf("%d %d %d\n",nex,ney,nez ); 73 vis[nez][nex][ney]=1; 74 q.push({nex,ney,nez,now.step+1}); 75 } 76 } 77 } 78 if(!flag) 79 printf("Trapped!\n"); 80 } 81 return 0; 82 83 }
标签:ini cap nes blank ems roc for body you
原文地址:https://www.cnblogs.com/codeoosacm/p/9917568.html