C - Dungeon Master

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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!
//用dfs做的,就是在试探的时候多试探一次上下位置的时候就行。

#include <iostream>
#include <queue>
#include <string.h>
using namespace std; struct point
{
int x,y,h;
int step;
};
point star,end; char map [][][];
bool way [][][];
int h,x,y; void read_map()//读地图
{
for (int i=;i<=h;i++)
{
for (int j=;j<=x;j++)
{
for (int k=;k<=y;k++)
{
cin>>map[i][j][k];
if (map[i][j][k]=='S')
{
star.h=i;
star.x=j;
star.y=k;
star.step=;
}
if (map[i][j][k]=='E')
{
end.h=i;
end.x=j;
end.y=k; }
}
}
}
} int check(point t)//检查是否能走
{ if ( t.x>= && t.x<=x && t.y>= && t.y<=y && t.h>= && t.h<=h && way[t.h][t.x][t.y]== )
{
if ( map[t.h][t.x][t.y]!='#')
{
return ;
}
}
return ;
} int bfs()
{
point now,next;
int min=-; queue<point> Q;
Q.push(star);
way[star.h][star.x][star.y]=; while (!Q.empty())
{
now=Q.front();
Q.pop();
if (now.x==end.x&&now.y==end.y&&now.h==end.h)
{
min=now.step;
break;
} next.x=now.x+;
next.y=now.y;
next.h=now.h;
next.step=now.step+;
if (check(next)){ Q.push(next); way[next.h][next.x][next.y]=;} next.x=now.x;
next.y=now.y-;
next.h=now.h;
next.step=now.step+;
if (check(next)){ Q.push(next); way[next.h][next.x][next.y]=;} next.x=now.x-;
next.y=now.y;
next.h=now.h;
next.step=now.step+;
if (check(next)){ Q.push(next); way[next.h][next.x][next.y]=;} next.x=now.x;
next.y=now.y+;
next.h=now.h;
next.step=now.step+;
if (check(next)){ Q.push(next); way[next.h][next.x][next.y]=;} next.x=now.x;
next.y=now.y;
next.h=now.h+;
next.step=now.step+;
if (check(next)){ Q.push(next); way[next.h][next.x][next.y]=;} next.x=now.x;
next.y=now.y;
next.h=now.h-;
next.step=now.step+;
if (check(next)){ Q.push(next); way[next.h][next.x][next.y]=;}
}
return min; } int main()
{
int all;
while (cin>>h>>x>>y)
{
memset(way,,sizeof(way));
if (h==&&x==&&y==) break;
read_map();
all=bfs();
if (all==-)
cout<<"Trapped!"<<endl;
else
cout<<"Escaped in "<<all<<" minute(s)."<<endl;
}
return ;
}

 

C - Dungeon Master的更多相关文章

  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 ...

  10. POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索)

    POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索) Description You ar ...

随机推荐

  1. hdu 5265 技巧题 O(nlogn)求n个数中两数相加取模的最大值

    pog loves szh II Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  2. POJ3525-Most Distant Point from the Sea(二分+半平面交)

    Most Distant Point from the Sea Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3955   ...

  3. hdu 5294 Tricks Device 最短路建图+最小割

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5294 Tricks Device Time Limit: 2000/1000 MS (Java/Other ...

  4. EChart-Timeline

    timeline-day.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...

  5. UIAlertViewController 2

    iOS 8的新特性之一就是让接口更有适应性.更灵活,因此许多视图控制器的实现方式发生了巨大的变化.全新的UIPresentationController在实现视图控制器间的过渡动画效果和自适应设备尺寸 ...

  6. xilinx平台DDR3设计教程之仿真篇_中文版教程

    https://wenku.baidu.com/view/ac32c8bcf705cc1754270923.html https://wenku.baidu.com/view/1d665697f185 ...

  7. Django的模型

    Django的模型类相当于数据库的一张表,模型类的实例对象相当于表中的一行内容 Django提供了多种创建对象的方式,常用如下: 通过create()方法 1.Person.objects.creat ...

  8. shell实现洗牌随机

    洗牌问题: 洗一副扑克,有什么好办法?既能洗得均匀,又能洗得快?即相对于一个文件来说怎样 高效率的实现乱序排列? 关于洗牌问题,其实已经有了一个很好的shell解法,这里另外给三个基于AWK的方法, ...

  9. 李洪强经典面试题53-Swift

    李洪强经典面试题53-Swift Swift 网上有很多Swift的语法题,但是Swift现在语法还未稳定,所以在这里暂时不贴出语法题,可以自行搜索. Swift和Objective-C的联系 Swi ...

  10. onkeypress、onkeydown、onkeyup

    在使用JavaScript做WEB键盘事件侦听捕获时,主要采用onkeypress.onkeydown.onkeyup三个事件进行出来.该三个事件的执行顺序如下:onkeydown -> onk ...