Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
WA WA WA niu niu niu#include<cstdio> #include<queue> #include<cstring> using namespace std; char mmp[50][50][50]; bool vis[50][50][50]; int l,r,c; int sx,sy,sz,ex,ey,ez; int dx[6]={-1,1,0,0,0,0}; int dy[6]={0,0,1,-1,0,0}; int dz[6]={0,0,0,0,1,-1}; struct node { int x,y,z,step; }; bool check(int x,int y,int z) { if(x>=l||y>=r||z>=c||x<0||y<0||z<0||mmp[x][y][z]=='#'||vis[x][y][z]==1) return true; return false; } int bfs() { node now,next; queue<node>Q; while(!Q.empty()) Q.pop(); now.x=sx,now.y=sy,now.z=sz,now.step=0; vis[now.x][now.y][now.z]=1; Q.push(now); while(!Q.empty()) { now=Q.front(); Q.pop(); if(now.x==ex&&now.y==ey&&now.z==ez) return now.step; for(int i=0;i<6;i++) { next.x=now.x+dx[i]; next.y=now.y+dy[i]; next.z=now.z+dz[i]; if(check(next.x,next.y,next.z)) continue; vis[next.x][next.y][next.z]=1; next.step=now.step+1; Q.push(next); } } return 0; } int main () { while(scanf("%d %d %d",&l,&r,&c)) { if(!l&&!r&&!c) break; getchar(); for(int i=0;i<l;i++) { for(int j=0;j<r;j++) { scanf("%s",mmp[i][j]); for(int k=0;k<c;k++) { if(mmp[i][j][k]=='S'){sx=i,sy=j,sy=k;} else if(mmp[i][j][k]=='E'){ex=i,ey=j,ez=k;} } } } memset(vis,0,sizeof(vis)); int ans=bfs(); if(ans) printf("Escaped in %d minute(s).\n",ans); else printf("Trapped!\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator