Dungeon Master
Dungeon Master
代码
c++
1 #include <iostream> 2 using namespace std; 3 int xx[6]={-1,1,0,0,0,0}, 4 yy[6]={0,0,-1,1,0,0}, 5 zz[6]={0,0,0,0,-1,1}; 6 int h[27001][5]; 7 bool a[31][31][31]; 8 int main () { 9 int l,r,c,t,w,x,y,z,fx,fy,fz; 10 char ch; 11 bool s; 12 while(cin>>l>>r>>c) 13 { 14 if(l==0&&r==0&&c==0) 15 return 0; 16 for(x=1;x<=l;++x) 17 for(y=1;y<=r;++y) 18 for(z=1;z<=c;++z) 19 { 20 cin>>ch; 21 if(ch=='S') 22 { 23 a[x][y][z]=false; 24 h[1][1]=x; 25 h[1][2]=y; 26 h[1][3]=z; 27 h[1][4]=0; 28 } 29 else if(ch=='E') 30 { 31 a[x][y][z]=true; 32 fx=x; 33 fy=y; 34 fz=z; 35 } 36 else if(ch=='#')a[x][y][z]=false; 37 else a[x][y][z]=true; 38 } 39 t=0; 40 w=1; 41 s=false; 42 do 43 { 44 t++; 45 for(int i=0;i<6;++i) 46 { 47 x=h[t][1]+xx[i]; 48 y=h[t][2]+yy[i]; 49 z=h[t][3]+zz[i]; 50 if(x>0&&x<=1&&y>0&&y<=r&&z>0&&z<=c&&a[x][y][z]) 51 { 52 a[x][y][z]=false; 53 w++; 54 h[w][1]=x; 55 h[w][2]=y; 56 h[w][3]=z; 57 h[w][4]=h[t][4]+1; 58 if(x==fx&&y==fy&&z==fz) 59 { 60 cout<<"Escaped in"<<h[w][4]<<"minute(s)."<<endl; 61 62 s=true; 63 break; 64 } 65 } 66 } 67 }while(t<w&&s==false); 68 if(s==false) 69 cout<<"Trapped!"<<endl; 70 } 71 return 0; 72 }
-The end-
2018.7.13

浙公网安备 33010602011771号