一本通上原题,洛谷上一模一样的(就少了个多组数据)都过了,why???
#include<bits/stdc++.h>
using namespace std;
int l,r,c,sx,sy,sz,ex,ey,ez;
bool a[35][35][35];
int dx[]={0,0,0,0,1,-1};
int dy[]={1,0,-1,0,0,0};
int dz[]={0,-1,0,1,0,0};
struct data{
int x,y,z,ans;
};
queue<data>Q;
void BFS(int X,int Y,int Z)
{
a[X][Y][Z]=0;
Q.push((data){X,Y,Z,0});
while(!Q.empty())
{
if(Q.front().x==ex && Q.front().y==ey && Q.front().z==ez)
{
printf("Escaped in %d minute(s).\n",Q.front().ans);
return ;
}
for(int i=0;i<6;i++)
{
int xx=Q.front().x+dx[i];
int yy=Q.front().y+dy[i];
int zz=Q.front().z+dz[i];
if(xx>0 && xx<=l && yy>0 && yy<=r && zz>0 && zz<=c && a[xx][yy][zz]==1)
{
a[xx][yy][zz]=0;
Q.push((data){xx,yy,zz,Q.front().ans+1});
}
}
Q.pop();
}
cout<<"Trapped!"<<endl;
}
int main()
{
ios::sync_with_stdio(0);
while(1)
{
memset(a,0,sizeof(a));
while(!Q.empty())Q.pop();
cin>>l>>r>>c;
if(l==0)break;
for(int i=1;i<=l;i++)
{
for(int j=1;j<=r;j++)
{
for(int k=1;k<=c;k++)
{
char temp;
cin>>temp;
if(temp=='.')a[i][j][k]=1;
if(temp=='S'){sx=i;sy=j;sz=k;a[i][j][k]=1;}
if(temp=='E'){ex=i;ey=j;ez=k;a[i][j][k]=1;}
}
}
}
BFS(sx,sy,sz);
}
return 0;
}