题目链接:https://cn.vjudge.net/contest/313994#problem/B
就是多加一维,其他没啥
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
int n,m,k;
int vis[33][33][33];
char a[33][33][33];
int tx[8] = {0,0,1,-1,0,0};
int ty[8] = {0,0,0,0,1,-1};
int tz[8] = {1,-1,0,0,0,0};
struct node
{
int x;
int y;
int k;
int step;
} now,after;
void BFS(int c,int s,int d)
{
now.x = s;
now.y = d;
now.k = c;
now.step = 0;
queue<struct node> q;
vis[now.k][now.x][now.y] = 1;
q.push(now);
while(!q.empty())
{
now = q.front();
q.pop();
if(a[now.k][now.x][now.y]=='E')
{
cout<<"Escaped in ";cout<<now.step;cout<<" minute(s)."<<endl;
return;
}
for(int i=0; i<6; i++)
{
after.x = now.x + tx[i];
after.y = now.y + ty[i];
after.k = now.k + tz[i];
if(after.k>=0&&after.k<k&&after.x>=0&&after.x<n&&after.y>=0&&after.y<m)
{
if(!vis[after.k][after.x][after.y]&&a[after.k][after.x][after.y]!='#')
{
after.step = now.step + 1;
vis[after.k][after.x][after.y] = 1;
q.push(after);
}
}
}
}
cout<<"Trapped!"<<endl;
}
int main()
{
ios::sync_with_stdio(false);
while(cin>>k>>n>>m&&n&&m&&k)
{
memset(vis,0,sizeof(vis));
int x,y,z,i,j;
for(i=0; i<k; i++)
{
for(j=0; j<n; j++)
{
cin>>a[i][j];
for(int p=0; p<m; p++)
{
if(a[i][j][p]=='S')
{
z = i;
x = j;
y = p;
}
}
}
}
BFS(z,x,y);
}
return 0;
}