#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
int x,y,z;
char maze[25][25][25];
bool vis[25][25][25];
int dir[6][3]={{0,0,1},{0,0,-1},{1,0,0},{-1,0,0},{0,-1,0},{0,1,0}};
bool in(int x1,int y1,int z1){
return x1>=0&&x1<x&&y1>=0&&y1<y&&z1>=0&&z1<z;
}
struct node{
int x,y,z,d;
node(int xx,int yy,int zz,int dd){
x=xx;
y=yy;
z=zz;
d=dd;
}
};
int bfs(int sx,int sy,int sz){
queue<node> q;
q.push(node(sx,sy,sz,0));
vis[sx][sy][sz]=true;
while(!q.empty()){
node now=q.front();
q.pop();
for(int i=0;i<6;i++){
int tx=now.x+dir[i][0];
int ty=now.y+dir[i][1];
int tz=now.z+dir[i][2];
if(in(tx,ty,tz)&&maze[tx][ty][tz]!='#'&&!vis[tx][ty][tz]){
if(maze[tx][ty][tz]=='E'){
return now.d+1;
}else{
vis[tx][ty][tz]=true;
q.push(node(tx,ty,tz,now.d+1));
}
}
}
}
return -1;
}
int main()
{
cin>>z>>x>>y;
int ix,iy,iz,ans;
while(x!=0&&y!=0&&z!=0){
memset(maze,0,sizeof(maze));
memset(vis,false,sizeof(vis));
for(int z1=0;z1<z;z1++){
for(int x1=0;x1<x;x1++){
for(int y1=0;y1<y;y1++){
cin>>maze[x1][y1][z1];
if(maze[x1][y1][z1]=='S'){
ix=x1;
iy=y1;
iz=z1;
}
}
}
}
ans=bfs(ix,iy,iz);
if(ans!=-1){
cout<<"Escaped in "<<ans<<" minute(s)."<<endl;
}else{
cout<<"Trapped!"<<endl;
}
cin>>z>>x>>y;
}
return 0;
}
9.9 分
1 人评分
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
发表评论 取消回复