三维迷宫不知道说啥。直接上代码了
#include <map>
#include <set>
#include <list>
#include <cmath>
#include<cctype>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b)
{
return a % b == 0 ? b : gcd(b, a % b);
}
#define MAXN 100000
struct node
{
int l,r,c;
int dist;
}q[MAXN];
int ans;
int start_l,start_r,start_c,end_l,end_r,end_c;
int dl[]={0,0,0,0,1,-1};
int dr[]={1,-1,0,0,0,0};
int dc[]={0,0,1,-1,0,0};
int L,R,C;
char G[35][35][35];
int vis[35][35][35];
bool flag;
void read()
{ flag=false;
memset(G,0,sizeof(G));
for (int i=0;i<L;i++)
for (int j=0;j<R;j++)
scanf("%s",G[i][j]);
for (int i=0;i<L;i++)
for (int j=0;j<R;j++)
for (int k=0;k<C;k++)
if (G[i][j][k]=='S') {start_l=i;start_r=j;start_c=k;}
else if (G[i][j][k]=='E') {end_l=i;end_r=j;end_c=k;}
}
void bfs()
{
memset(vis,0,sizeof(vis));
int front=0,rear=1;
q[0].l=start_l;q[0].r=start_r;q[0].c=start_c;
q[0].dist=0;
vis[q[0].l][q[0].r][q[0].c]=1;
node u,s;
while (front<rear)
{
u=q[front];
if (u.l==end_l && u.r==end_r && u.c==end_c)
{
ans=u.dist;
return ;
}
for (int d=0;d<6;d++)
{
int nl=u.l+dl[d];
int nr=u.r+dr[d];
int nc=u.c+dc[d];
if (nl>=0 && nl<L && nr>=0 && nr<R && nc>=0 && nc<C && !vis[nl][nr][nc] && G[nl][nr][nc]!='#')
{
s.l=nl;s.r=nr;s.c=nc;s.dist=u.dist+1;
q[rear++]=s;
vis[nl][nr][nc]=1;
}
}
front++;
}
}
int main()
{
//freopen("sample.txt","r",stdin);
while (scanf("%d%d%d",&L,&R,&C)==3)
{
//if ((L==1 && R==1 && C==1)) {scanf("%*c%c",&a);printf("Trapped!\n");continue;}
if (L==0 && R==0 && C==0) break;
read();
ans=0;
bfs();
if (ans!=0) printf("Escaped in %d minute(s).\n",ans);
else printf("Trapped!\n");
}
return 0;
}