Dungeon Master

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 46   Accepted Submission(s) : 16
Problem Description
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 form

Escaped 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 line

Trapped!

 
Sample Input
3 4 5
S....
.###.
.##..
###.# #####
#####
##.##
##... #####
#####
#.###
####E 1 3 3
S##
#E#
### 0 0 0
 
Sample Output
Escaped in 11 minute(s).
Trapped!
 
#include<stdio.h>
#include<queue>
#include<string.h>
using namespace std;
char map[31][31][31];
int vis[31][31][31];
int dx[6]={1,0,-1,0,0,0};
int dy[6]={0,0,0,1,0,-1};
int dz[6]={0,1,0,0,-1,0};
int x,y,z,ex,ey,ez,m,n,l;
struct node
{
int x,y,z;
int step;
friend bool operator< (node n1,node n2)
{
return n1.step>n2.step;
}
}p,temp;
bool judge(node r)
{
if(r.x<0||r.x>=m||r.y<0||r.y>=n||r.z<0||r.z>=l)
return true;
if(vis[r.x][r.y][r.z]||map[r.x][r.y][r.z]=='#')
return true;
return false;
}
int bfs()
{
memset(vis,0,sizeof(vis));
priority_queue<node>q;
while(!q.empty()) q.pop();
p.x=x;
p.y=y;
p.z=z;
p.step=0;
q.push(p);
vis[x][y][z]=1;
while(!q.empty())
{
p=q.top();
q.pop();
if(p.x==ex&&p.y==ey&&p.z==ez)
{
return p.step;
}
for(int i=0;i<6;i++)
{
temp=p;
temp.x=p.x+dx[i];
temp.y=p.y+dy[i];
temp.z=p.z+dz[i];
if(judge(temp))
continue;
vis[temp.x][temp.y][temp.z]=1;
temp.step=p.step+1;
q.push(temp);
}
}
return 0;
}
int main()
{
while(scanf("%d%d%d",&m,&n,&l)!=EOF)
{
memset(map,'\0',sizeof(map));
getchar();
if(m+n+l==0)
break;
int i,j,k;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
scanf("%s",&map[i][j]);
for(k=0;k<l;k++)
{ if(map[i][j][k]=='S')
{
x=i;y=j;z=k;
}
if(map[i][j][k]=='E')
{
ex=i;ey=j;ez=k;
}
}
//getchar();
}
/*for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
for(k=0;k<l;k++)
printf("%c",map[i][j][k]);
printf("\n");
}*/
//printf("%d %d %d %d %d% d",x,y,z,ex,ey,ez);
int ans=bfs();
if(ans!=0)
printf("Escaped in %d minute(s).\n",ans);
else
printf("Trapped!\n");
}
return 0;
}

Dungeon Master hdoj的更多相关文章

  1. POJ 2251 Dungeon Master(3D迷宫 bfs)

    传送门 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 11 ...

  2. poj 2251 Dungeon Master

    http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  3. Dungeon Master 分类: 搜索 POJ 2015-08-09 14:25 4人阅读 评论(0) 收藏

    Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20995 Accepted: 8150 Descr ...

  4. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  5. UVa532 Dungeon Master 三维迷宫

        学习点: scanf可以自动过滤空行 搜索时要先判断是否越界(L R C),再判断其他条件是否满足 bfs搜索时可以在入口处(push时)判断是否达到目标,也可以在出口处(pop时)   #i ...

  6. Dungeon Master poj 2251 dfs

    Language: Default Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16855 ...

  7. POJ 2251 Dungeon Master(地牢大师)

    p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...

  8. BFS POJ2251 Dungeon Master

    B - Dungeon Master Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  9. POJ 2251 Dungeon Master (非三维bfs)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 55224   Accepted: 20493 ...

随机推荐

  1. SLAM: 图像角点检测的Fast算法(时间阈值实验)

    作为角点检测的一种快速方法,FastCornerDetect算法比Harris方法.SIft方法都要快一些,应用于实时性要求较高的场合,可以直接应用于SLAM的随机匹配过程.算法来源于2006年的Ed ...

  2. C#访问Win 32的一些尝试

    使用C#调用Win 32 Api大部分情况下基本只涉及到参数类型的转变,但在遇到Win 32 Api返回LPVOID *lpBuff 时会遇到一些解析遍历难题.lpBuff为二维指针,*lpBuff是 ...

  3. (1)dotnet开源电商系统-brnshop&brnMall 和老外开发的nopCommerce(dotnet两套电商来PK--第一篇)

    一直想做电商软件,但是实在不想学PHP了,所以前后关注了这两个开源电商系统.一个是国人出品的,一个据说是俄罗斯人写得(不知道对不对).目前两个开源软件都在学习了解中,以下的博文可能会涉及到这两套系统, ...

  4. (转)基于Metronic的Bootstrap开发框架经验总结(9)--实现Web页面内容的打印预览和保存操作

    http://www.cnblogs.com/wuhuacong/p/5147368.html 在前面介绍了很多篇相关的<Bootstrap开发框架>的系列文章,这些内容基本上覆盖到了我这 ...

  5. handyJson的技术内核

    1.swift对象内存模型: 2.指针操作: 3.协议.泛型.扩展: 4.kvc: 1是所有实现的基础,没有内存对象(类)模型,后面的一切都我从谈起. 在1的基础上使用2进行对象模型信息的提取和转换. ...

  6. sturts2 回顾

    第一个简单的struts2例子: 1.  创建一个web project 2.  导入jar包 具体jar包在struts 的例子中的lib文件夹中copy

  7. javeee 字节Buffered

    package Zy; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io. ...

  8. day004 与用户交互、格式化输出、基本运算符

    目录 今天Python所学习的知识如下:①与用户的交互.格式化输出.基本运算符.以下整理汇总下所学习的知识点. 与用户的交互 input 注意事项: input函数接受的都是字符串 python2中的 ...

  9. 死磕itchat源码--core.py

    core.py文件中的Core类定义了itchat的所有接口.且,仅仅是定义了接口,全部在component包中实现重构.其用法如下表述: 缺省 源码如下: # -*- encoding: utf-8 ...

  10. 莫烦大大keras学习Mnist识别(3)-----CNN

    一.步骤: 导入模块以及读取数据 数据预处理 构建模型 编译模型 训练模型 测试 二.代码: 导入模块以及读取数据 #导包 import numpy as np np.random.seed(1337 ...