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. Intellij IDEA 2018.3.5版安装详解及破解

    几个参考链接: 软件下载链接:https://www.jetbrains.com/idea/ 破解补丁:链接:https://pan.baidu.com/s/1xUbil5jq_DyTbXJWUUsM ...

  2. ie8及其以下版本兼容性问题之placeholder实现

    1. 普通浏览器下修改placeholder颜色 因为每个浏览器的CSS选择器都有所差异,所以需要针对每个浏览器做单独的设定. 示例: input::-webkit-input-placeholder ...

  3. 控制台输入年龄,根据年龄输出不同的提示 ------if……else if ……else 语句

    package com.zuoye.test; import java.util.Scanner; public class Nianling { public static void main(St ...

  4. 【PostgreSQL-9.6.3】函数(3)--日期和时间函数

    在PostgreSQL中,DATE.TIME.TIMESTAMP是三种不同的数据类型.DATE表示日期类型,格式为YYYY-MM-DD或YYYYMMDD:TIME表示时间类型,格式为hh:mi:ss: ...

  5. C#如何判断操作系统语言版本

    using System.Runtime.InteropServices; static void Main(string[] args) { System.Console.WriteLine(Sys ...

  6. Java继承实现接口的抽象类

    1.TestIntace.java package com.chase.abstrac; /** * 接口 * @author Chase * * @date 2013-10-21 下午02:29:1 ...

  7. phtoshop CC2018破解简单过程

    1.下载adobe photoshop cc 2018(可以用360安全卫士下载)-->并安装2.下载破解补丁,破解补丁下载地址:http://www.xue51.com/soft/1377.h ...

  8. Python【每日一问】35

    问: 基础题: 从键盘输入4个数字,各数字采用空格分隔,对应为变量x0,y0,x1,y1.计算(x0,y0)和(x1,y1)两点之间的距离,输出结果保留1位小数. 比如,键盘输入:0 1 3 5,屏幕 ...

  9. NFS实时备份

    方法一(inotify+rsync): 1.安装inotify-tools(客户端)[监听工具],实现数据属实备份检查目录是否有如下文档,没有表示操作系统不支持 ls -l /proc/sys/fs/ ...

  10. jQuery(UI)常用插件

    jQuery 官方网站:http://jquery.com/ 下载地址:http://jquery.com/download/ 插件地址: http://plugins.jquery.com/ 常用插 ...