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. 倍福TwinCAT(贝福Beckhoff)应用教程13.2 TwinCAT控制松下伺服 CS说明

    虚拟仿真上,要注意仿真只是为了可视化,可以看到数据的变动是否和实际一致,所以Robot2D才是主要因素,虚拟仿真采集机器人的关节位置或者TCP位置来显示而已,为了测试一些别的算法,我们还可以在虚拟仿真 ...

  2. C#和Java中字符串的异同

    字符串 在底层上跟C#类似,每个字符串的实例都不可修改.当修改字符串变量时,是将变量指向新的字符串实例,而不是修改原本的实例.Java中也有字符串池机制. 注意:使用 == 运算符比较字符串时,跟C# ...

  3. B10:迭代器模式 Iterator

    提供了一种方法顺序访问一个聚合对象中各个元素,而又不暴露该对象的内部表示. 适用场景:当你需要访问一个聚合对象,而这个对象不论是什么,你都需要遍历的时候,就用迭代器. UML: 示例代码: class ...

  4. 经典SQL语句使用方法大全

    一.基础1.说明:创建数据库CREATE DATABASE database-name2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备份数 ...

  5. iOS 自定义转场动画浅谈

    代码地址如下:http://www.demodashi.com/demo/11612.html 路漫漫其修远兮,吾将上下而求索 前记 想研究自定义转场动画很久了,时间就像海绵,挤一挤还是有的,花了差不 ...

  6. python学习日记:np.newaxis

    import numpy as np label = np.array([[1,2,3,4],[5,6,7,8]])print (label.shape)label = label[np.newaxi ...

  7. mongoDB id 导出,dump,sed,count,mysql import等用法示例

    #count collectiondb.news.count({"lpublishtime":{"$gte":1358697600000}}); #mongo导 ...

  8. udpsocket 通信C#例子

    服务端代码: using System; using System.Collections.Generic; using System.Linq; using System.Net; using Sy ...

  9. PHP正则表达式教程

    1.入门简介  在编写处理字符串的程序或网页时,经常会有查找符合某些复杂规则的字符串的需要.正则表达式就是用于描述这些规则的工具.换句话说,正则表达式就是记录文本规则的代码. 很可能你使用过Windo ...

  10. JAVA代码之RocketMQ生产和消费数据

    一.启动RocketMQ [root@master ~]# cat /etc/hosts # Do not remove the following line, or various programs ...