这题想起魔方了,改改A了2225
#include<iostream>
using namespace std;
char dung[35][35][35];
bool visit[35][35][35];
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
int dx[6]=
{-1,0,0,0,0,1};
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
int dy[6]=
{0,-1,0,0,1,0};
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
int dz[6]=
{0,0,-1,1,0,0};
int que[82000];//3*30*30*30,一开始开得太小了
2700,27000,30000,40000,50000,640000全TM的WA||RE
int L,R,C;
int sx,sy,sz,ex,ey,ez;
int step;
void bfs()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
{
int i,x,y,z,tx,ty,tz;
int rear,front,trear;
bool reach=false;
memset(que,0,sizeof(que));
rear=front=0;
que[rear++]=sx;
que[rear++]=sy;
que[rear++]=sz;
visit[sx][sy][sz]=true;
while(front<rear )//&& !visit[ex][ey][ez])
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(visit[ex][ey][ez])
{reach=true;break;}//找到E,停
trear=rear;
step++;
while(front<trear )//&& !visit[ex][ey][ez])
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//if(visit[ex][ey][ez]) {reach=true;break;}
x=que[front++];
y=que[front++];
z=que[front++];
for(i=0;i<6;i++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
tx=x+dx[i];
ty=y+dy[i];
tz=z+dz[i];
if(tx>=0 && tx<L && ty>=0 && ty<R && tz>=0 && tz<C && !visit[tx][ty][tz] && dung[tx][ty][tz]!='#')
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
visit[tx][ty][tz]=true;
que[rear++]=tx;
que[rear++]=ty;
que[rear++]=tz;
}
}//for
}//while
}//while
if(!reach) step=-1;//找不到E,trapped
}
int main()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
{
int i,j,k;
while(scanf("%d%d%d",&L,&R,&C)!=EOF && L && R && C)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
memset(visit,0,sizeof(visit));
for(i=0;i<L;i++)
for(j=0;j<R;j++)
scanf(" %s",dung[i][j]);
for(i=0;i<L;i++)
for(j=0;j<R;j++)
for(k=0;k<C;k++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(dung[i][j][k]=='S')
{sx=i;sy=j;sz=k;}
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
else if(dung[i][j][k]=='E')
{ex=i;ey=j;ez=k;}
}
step=0;
bfs();
if(step==-1) printf("Trapped!\n");
else printf("Escaped in %d minute(s).\n",step);
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
}
return 0;
}
posted on 2009-07-23 11:39
wyiu 阅读(558)
评论(0) 编辑 收藏 引用 所属分类:
POJ