3D dungeon
来源:互联网 发布:国外ed2k下载软件 编辑:程序博客网 时间:2024/05/12 20:41
A - 签到题Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %lluDescription
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid rock on all sides. Is an escape possible? If yes, how long will it take?Input
The input consists of a number of dungeons. Each dungeon description starts with a line containing three integers L, R and C (all limited to 30 in size). L is the number of levels making up the dungeon. R and C are the number of rows and columns making up the plan of each level. Then there will follow L blocks of R lines each containing C characters. Each character describes one cell of the dungeon. A cell full of rock is indicated by a '#' and empty cells are represented by a '.'. Your starting position is indicated by 'S' and the exit by the letter 'E'. There's a single blank line after each level. Input is terminated by three zeroes for L, R and C.Output
Each maze generates one line of output. If it is possible to reach the exit, print a line of the formEscaped in x minute(s).where x is replaced by the shortest time it takes to escape. If it is not possible to escape, print the lineTrapped!Sample Input
3 4 5S.....###..##..###.#############.####...###########.#######E1 3 3S###E####0 0 0Sample Output
Escaped in 11 minute(s).Trapped!
#include<stdio.h>#include <iostream>#include<string.h>#include<queue>using namespace std;char a[31][31][31];int nz[6]={0,0,0,0,1,-1},ny[6]={1,-1,0,0,0,0},nx[6]={0,0,-1,1,0,0};int bx,by,bz;int l,r,c,num;struct node{ int x; int y; int z; int s;};queue<node>Q;int judge(int x,int y,int z){ if(x<0||x>l||y<0||y>r||z<0||z>c) return 0; return 1;}int bfs(){ int i,j; queue<node>Que; node q,p; q.x=bx; q.y=by; q.z=bz; q.s=0; a[bx][by][bz]='#';//将s标记为#,表示已走过 Que.push(q);//入队 while(!Que.empty()) { p=Que.front(); Que.pop(); for(i=0;i<6;i++) { q=p; q.x=q.x+nx[i]; q.y=q.y+ny[i]; q.z=q.z+nz[i]; q.s++; if(judge(q.x,q.y,q.z)==0)//判断越界 continue; if(a[q.x][q.y][q.z]=='E') { num=q.s; return 1;} if(a[q.x][q.y][q.z]=='.') { a[q.x][q.y][q.z]='#'; Que.push(q); } } } return 0;}int main(){ int i,j,k,flag; while(~scanf("%d %d %d",&l,&r,&c)) { num=0; if(l==0&&r==0&&c==0) break; flag=0; for(i=0;i<l;i++) for(j=0;j<r;j++) scanf("%s",a[i][j]); for(i=0;i<l;i++) for(j=0;j<r;j++) for(k=0;k<c;k++) { if(a[i][j][k]=='S') { bx=i; by=j; bz=k; i=l; j=r; k=c; } } if(bfs()) { printf("Escaped in %d minute(s).\n",num); } else printf("Trapped!\n"); } return 0;}
0 0
- 3D dungeon
- 3D dungeon
- 3D dungeon
- nyoj353 3D dungeon
- 3D dungeon
- 3D dungeon
- NYOJ353 3D dungeon 【BFS】
- NYOJ 353 3D dungeon
- 353 3D dungeon【bfs】
- NYOJ 353-3D dungeon
- NYOJ 353 3D dungeon
- 3D dungeon(bfs)
- 题目353:3D dungeon
- NYOJ 353 3D dungeon + zoj 1940 Dungeon Master
- NYOJ 353 3D dungeon 【bfs】
- nyoj 353 3D dungeon 【bfs】
- NYOJ 353--3D dungeon【水题 && BFS】
- NYOJ 353 3D dungeon (BFS)
- Java应用架构设计的七次重构详解
- jQuery+turn.js翻书、文档和杂志3种特效演示
- 2016年11月09日-晚间金市金价美国埃文斯市场量能通胀
- Servlet解决doGet和doPost参数乱码问题
- Delphi 部分API
- 3D dungeon
- iOS 10.0 10.1 真机调试包
- 1057.盖房子
- jobtracker running as process 2103. Stop it first
- 技术点集(面试)
- java基础(四)——面向对象_类、封装、构造器、this
- android scrollView中使用viewpager 不显示的解决方法
- matlab2012b 小波变换工具箱的使用(一)工具箱打开及一维小波的显示与系数提取
- CSS3属性transform详解之(旋转:rotate,缩放:scale,倾斜:skew,移动:translate)