Dungeon Master

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 18   Accepted Submission(s) : 12
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!
 
Source
PKU
 
 
 
又一道BFS水题,我发现我刷搜索水题很溜啊哈哈。。
 
 
#include<iostream>
#include<cstring>
using namespace std;
char cube[31][31][31];
bool sign[31][31][31];
int L,R,C; struct pos
{
int l,r,c;
}; pos que[54000],beg;
int step[54000];
int BFS()
{
int front=0,rear=1;
que[0]=beg;
sign[que[0].l][que[0].r][que[0].c]=true;
while(front<rear)
{
if(que[front].l-1>=0&&!sign[que[front].l-1][que[front].r][que[front].c]&&cube[que[front].l-1][que[front].r][que[front].c]!='#')
{
que[rear]=que[front];
que[rear].l=que[front].l-1;
sign[que[rear].l][que[rear].r][que[rear].c]=true;
step[rear]=step[front]+1;
if(cube[que[rear].l][que[rear].r][que[rear].c]=='E')
return step[rear];
rear++;
}
if(que[front].l+1<L&&!sign[que[front].l+1][que[front].r][que[front].c]&&cube[que[front].l+1][que[front].r][que[front].c]!='#')
{
que[rear]=que[front];
que[rear].l=que[front].l+1;
sign[que[rear].l][que[rear].r][que[rear].c]=true;
step[rear]=step[front]+1;
if(cube[que[rear].l][que[rear].r][que[rear].c]=='E')
return step[rear];
rear++;
}
if(que[front].r-1>=0&&!sign[que[front].l][que[front].r-1][que[front].c]&&cube[que[front].l][que[front].r-1][que[front].c]!='#')
{
que[rear]=que[front];
que[rear].r=que[front].r-1;
sign[que[rear].l][que[rear].r][que[rear].c]=true;
step[rear]=step[front]+1;
if(cube[que[rear].l][que[rear].r][que[rear].c]=='E')
return step[rear];
rear++;
}
if(que[front].r+1<R&&!sign[que[front].l][que[front].r+1][que[front].c]&&cube[que[front].l][que[front].r+1][que[front].c]!='#')
{
que[rear]=que[front];
que[rear].r=que[front].r+1;
sign[que[rear].l][que[rear].r][que[rear].c]=true;
step[rear]=step[front]+1;
if(cube[que[rear].l][que[rear].r][que[rear].c]=='E')
return step[rear];
rear++;
}
if(que[front].c-1>=0&&!sign[que[front].l][que[front].r][que[front].c-1]&&cube[que[front].l][que[front].r][que[front].c-1]!='#')
{
que[rear]=que[front];
que[rear].c=que[front].c-1;
sign[que[rear].l][que[rear].r][que[rear].c]=true;
step[rear]=step[front]+1;
if(cube[que[rear].l][que[rear].r][que[rear].c]=='E')
return step[rear];
rear++;
}
if(que[front].c+1<C&&!sign[que[front].l][que[front].r][que[front].c+1]&&cube[que[front].l][que[front].r][que[front].c+1]!='#')
{
que[rear]=que[front];
que[rear].c=que[front].c+1;
sign[que[rear].l][que[rear].r][que[rear].c]=true;
step[rear]=step[front]+1;
if(cube[que[rear].l][que[rear].r][que[rear].c]=='E')
return step[rear];
rear++;
}
front++;
}
return -1;
} int main()
{
while(cin>>L>>R>>C&&(R+C+L))
{
int i,j,k;
memset(sign,false,sizeof(sign));
memset(step,0,sizeof(step));
for(i=0;i<L;i++)
{
for(j=0;j<R;j++)
for(k=0;k<C;k++)
{
cin>>cube[i][j][k];
if(cube[i][j][k]=='S')
{
beg.l=i;
beg.r=j;
beg.c=k;
}
}
}
int ans=BFS();
if(ans==-1)
cout<<"Trapped!"<<endl;
else
cout<<"Escaped in "<<ans<<" minute(s)."<<endl; }
}
 

HDOJ-三部曲一(搜索、数学)-1005-Dungeon Master的更多相关文章

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

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

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

  3. Dungeon Master POJ - 2251 (搜索)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 48605   Accepted: 18339 ...

  4. Dungeon Master hdoj

    Dungeon Master Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Tot ...

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

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

  6. UVa532 Dungeon Master 三维迷宫

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

  7. POJ 2251 Dungeon Master【三维BFS模板】

    Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45743 Accepted: 17256 Desc ...

  8. BFS POJ 2251 Dungeon Master

    题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...

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

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

  10. poj 2251 Dungeon Master

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

随机推荐

  1. python2 安装scrapy问题解决方法

    错误代码: build/temp.linux-x86_64-:: fatal error: openssl/opensslv.h: 没有那个文件或目录 compilation terminated. ...

  2. (31)odoo中的时间

    * 在model中    from datetime import datetime, timedelta    import time        from openerp.tools impor ...

  3. js字符串处理

    1.获取字符串实际长度 var jmz = {}; function strlen(str) { ///<summary>获得字符串实际长度,中文2,英文1</summary> ...

  4. 问题解决The connection to adb is down, and a severe error has occured.

    遇到问题描述: 运行android程序控制台输出 [2013-06-25 11:10:32 - MyWellnessTracker] The connection to adb is down, an ...

  5. Java多线程-新特征-锁(下)

    在上文中提到了Lock接口以及对象,使用它,很优雅的控制了竞争资源的安全访问,但是这种锁不区分读写,称这种锁为普通锁.为了提高性能,Java提供了读写锁,在读的地方使用读锁,在写的地方使用写锁,灵活控 ...

  6. Hadoop作业JVM堆大小设置优化 [转]

    前段时间,公司Hadoop集群整体的负载很高,查了一下原因,发现原来是客户端那边在每一个作业上擅自配置了很大的堆空间,从而导致集群负载很高.下面我就来讲讲怎么来现在客户端那边的JVM堆大小的设置.我们 ...

  7. phonegap开发入门

    做了几次开发配置了,但时间一长就忘了,特记录一下. 一.环境变量配置::右击“我的电脑”-->"高级"-->"环境变量" 1.在系统变量里新建JAV ...

  8. ACM心情总结

    已经快要12点了,然而还有5000字概率论论文没有动.在论文里,我本来是想要总结一下ACM竞赛中出现过的概率论题目,然而当敲打第一段前言的时候,我就迟疑了. 我问自己,ACM竞赛到底有什么现实意义. ...

  9. PowerMock遇到的问题——3

    在用WhiteBox调用对象的私有方法时,如果要传的参数为空,如果直接在参数列表中写null的话,可能会报空指针异常,可以定义一个变量使他等于空,再把变量传进去就可以了.

  10. jmeter之json数据参数化 断言等

    在 http Load Testing 中,json 数据的提交是个让人头疼的问题.本文详细介绍如何进行 JMeter 的 json 测试提交,以及如何将其参数化.Step 1 http json 请 ...