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. oneapm的技术博客(简书),用来追溯群里的讨论,mark

    http://www.jianshu.com/users/572133740c3f/latest_articles

  2. 配置git账号和密码

    最开始启动的时候 配置用户名和用户邮箱,安装完git第一件要做的事情! git config --global uesr.name "Sunnshino" git config - ...

  3. XML之Schema

    前面学习了DTD.相同我们有了一套更完好的定义法则-Schema. 以下环绕Schema是什么.为何用以及怎么用谈谈自己的感受. XML Schema是基于XML的DTD替代者. XML Schema ...

  4. 转:nolock的替代方案-提交读快照隔离[行版本控制]

    with(nolock)并意味着没有锁,实际上在查询一张表时,还是有锁,会对对象增加架构锁, 防止表会修改,会对数据库增加共享锁.若使用drop index,则要等到架构锁释放.   sql serv ...

  5. redis 使用内存超过maxmemory

    redis使用量超过了maxmemory,这时无法增加最大内存,redis 实例没有可用内存,导致命令都会执行失败 (error) OOM command not allowed when used ...

  6. SQl查询数据库表名、表的列名、数据类型、主键

    1.获取所有数据库名:     2.Select Name FROM Master..SysDatabases order by Name   3.  4.2.获取所有表名:   5.   (1)  ...

  7. C++语言基础(12)-虚函数

    一.虚函数使用的注意事项 1.只需要在虚函数的声明处加上 virtual 关键字,函数定义处可以加也可以不加. 2.为了方便,你可以只将基类中的函数声明为虚函数,这样所有子类中具有遮蔽(覆盖)关系的同 ...

  8. c++ about SLL(Static-Link Library) and DLL(Dynamic-Link Library)

    First thing first, Wiki: http://en.wikipedia.org/wiki/Dynamic-link_library http://en.wikipedia.org/w ...

  9. Redis的README.md

    This README is just a fast *quick start* document. You can find more detailed documentation at http: ...

  10. virtualBox centos 6.x不能联网

    sudo vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 TYPE=Ethernet UUID=3323da63---89bb-92 ...