灰常开心,1A的题,虽然很水,但是还是很开心啦,
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue>
using namespace std;
int move[6][3] = {{0,0,1}, {0,0,-1}, {0,1,0}, {0,-1,0}, {1,0,0}, {-1,0,0}};
bool vis[50][50][50];
int row,clo,hig;
int ans = 0;
char gra[50][50][50];
struct point
{
int x;
int y;
int z;
int step;
}now,temp;
bool check(int x, int y, int z)
{
if(x >= 0 && x < row && y >= 0 && y < clo && z >= 0 && z < hig && gra[x][y][z] != '#' )
return true;
return false;
}
int sx,sy,sz,ex,ey,ez;
void bfs()
{
queue<point>que;
now.x = sx;
now.y = sy;
now.z = sz;
now.step = 0;
vis[now.x][now.y][now.z] = true;
que.push(now);
while(!que.empty())
{
now = que.front();
que.pop();
if(now.x == ex && now.y == ey && now.z == ez)
{
ans = now.step ;
break;
}
for( int i = 0; i < 6; i++)
{
temp.x = now.x + move[i][0];
temp.y = now.y + move[i][1];
temp.z = now.z + move[i][2];
temp.step = now.step + 1;
if(check(temp.x,temp.y,temp.z) && !vis[temp.x][temp.y][temp.z])
{
//cout<<temp.x<<temp.y<<temp.z<<endl;
que.push(temp);
vis[temp.x][temp.y][temp.z] = true;
}
}
}
return ;
}
int main()
{
while(scanf("%d %d %d", &hig, &row, &clo)!=EOF,hig && row &&clo)
{
ans = 0;
memset(vis,0,sizeof(vis));
for( int i = 0; i<hig; i++)
{
for( int j = 0; j<row; j++)
{
for( int k = 0; k<clo; k++)
{
cin>>gra[j][k][i];
if(gra[j][k][i] == 'S')
{
sx = j; sy = k; sz = i;
}
else if(gra[j][k][i] == 'E')
{
ex = j; ey = k; ez = i;
}
}
getchar();
}
}
bfs();
if(ans == 0)
printf("Trapped!\n");
else
printf("Escaped in %d minute(s).\n",ans);
}
return 0;
}