标签:ica vector ace line front limit which lan span
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 "stdlib.h" 3 #include "iostream" 4 #include "algorithm" 5 #include "string" 6 #include "cstring" 7 #include "queue" 8 #include "cmath" 9 #include "vector" 10 #include "map" 11 #include "set" 12 #define mj 13 #define db double 14 #define ll long long 15 using namespace std; 16 const int N=1e8+5; 17 const int mod=1e9+7; 18 const ll inf=1e16+10; 19 bool v[35][35][35]; 20 int dx[6]={0,0,1,0,-1,0},dy[6]={0,0,0,1,0,-1},dz[6]={-1,1,0,0,0,0}; 21 int a,b,c; 22 char s[35][35][35]; 23 int d[35][35][35]; 24 typedef struct P{ 25 int x,y,z; 26 P(int c,int d,int e){ 27 z=c,x=d,y=e; 28 } 29 }; 30 void bfs(P t){ 31 queue<P> q; 32 for(int i=0;i<35;i++) 33 for(int j=0;j<35;j++) 34 for(int k=0;k<35;k++) 35 d[i][j][k]=N; 36 q.push(t); 37 memset(v,0, sizeof(v)); 38 d[t.z][t.x][t.y]=0; 39 v[t.z][t.x][t.y]=1; 40 while(q.size()){ 41 P p=q.front(); 42 q.pop(); 43 if(s[p.z][p.x][p.y]==‘E‘){ 44 printf("Escaped in %d minute(s).\n",d[p.z][p.x][p.y]); 45 return; 46 } 47 48 for(int i=0;i<6;i++){ 49 int nx=p.x+dx[i],ny=p.y+dy[i],nz=p.z+dz[i]; 50 if(0<=nx&&nx<b&&0<=ny&&ny<c&&0<=nz&&nz<a&&s[nz][nx][ny]!=‘#‘&&!v[nz][nx][ny]){ 51 d[nz][nx][ny]=d[p.z][p.x][p.y]+1; 52 q.push(P(nz,nx,ny)); 53 v[nz][nx][ny]=1; 54 55 } 56 } 57 58 } 59 printf("Trapped!\n"); 60 61 62 } 63 int main() 64 { 65 while(scanf("%d%d%d",&a,&b,&c)==3,a||b||c){ 66 int t=a; 67 int x,y,z; 68 memset(s,‘\0‘, sizeof(s));// 一开始把x,y,z搞反了,调了好一会 69 for(int i=0;i<t;i++){ 70 for(int j=0;j<b;j++){ 71 scanf("%s",s[i][j]); 72 for(int k=0;k<c;k++) 73 if(s[i][j][k]==‘S‘) x=j,y=k,z=i; 74 } 75 } 76 bfs(P(z,x,y)); 77 } 78 return 0; 79 }
标签:ica vector ace line front limit which lan span
原文地址:http://www.cnblogs.com/mj-liylho/p/7183869.html