POJ 2251
来源:互联网 发布:主域名服务器怎么填 编辑:程序博客网 时间:2024/06/07 23:36
char pic[40][40][40];bool vis[40][40][40];int dx[]={0,0,-1,1,0,0};int dy[]={-1,1,0,0,0,0};int dz[]={0,0,0,0,-1,1};int ans,l,r,c;int sx,sy,sz,ex,ey,ez;typedef struct mapnode{ int x;int y;int z; int time;}node;int bfs(){ queue<node>q; node def;def.x=sx;def.y=sy;def.z=sz;def.time=0; q.push(def); while(!q.empty()) { node tmp=q.front(); q.pop(); //cout<<tmp.time<<endl; //cout<<ex<<ey<<ez<<endl; //cout<<tmp.x<<tmp.y<<tmp.z<<endl; if(tmp.x==ex&&tmp.y==ey&&tmp.z==ez) return tmp.time; int tx=tmp.x,ty=tmp.y,tz=tmp.z,tt=tmp.time; for(int i=0;i<6;i++) { if(!vis[tx+dx[i]][ty+dy[i]][tz+dz[i]] &&pic[tx+dx[i]][ty+dy[i]][tz+dz[i]]!='#' &&tx+dx[i]>=0&&tx+dx[i]<l &&ty+dy[i]>=0&&ty+dy[i]<r &&tz+dz[i]>=0&&tz+dz[i]<c) { tmp.x=tx+dx[i]; tmp.y=ty+dy[i]; tmp.z=tz+dz[i]; tmp.time=tt+1; vis[tx+dx[i]][ty+dy[i]][tz+dz[i]]=1; q.push(tmp); } } } return 0;}int main(){ //freopen("test.txt","r",stdin); while(scanf("%d%d%d\n",&l,&r,&c)&&l&&r&&c) { memset(vis,0,sizeof(vis)); for(int i=0;i<l;i++,getchar()) for(int j=0;j<r;j++,getchar()) for(int k=0;k<c;k++) { scanf("%c",&pic[i][j][k]); if(pic[i][j][k]=='S') sx=i,sy=j,sz=k; if(pic[i][j][k]=='E') ex=i,ey=j,ez=k; } ans=bfs(); if(ans)printf("Escaped in %d minute(s).\n",ans); else printf("Trapped!\n"); } return 0;}
0 0
- POJ-2251
- POJ 2251
- poj 2251
- poj 2251
- POJ 2251
- poj 2251
- POJ 2251
- POJ 2251
- poj 2251
- poj-2251
- poj 2251
- POJ 2251
- poj 2251
- poj 2251
- poj 2251
- poj 2251
- 2251POJ
- poj-2251
- pkg-config
- Sass的简单使用
- 判断一个shape是折线还是弧段
- lua学习(一)
- 图片转base64文字
- POJ 2251
- C++和C中将数字和字符串互相转换的方法
- ADT 二叉查找树
- get、post区别
- C++环境测试CPU是否支持MMX,SSE-未完
- 一个略微复杂的Sql行转列实例
- 前台线程与后台线程的区别
- code clean
- svn 的基本操作 checkout