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!
 

//一次AC。感觉太爽了。!

#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
char map[40][40][40];
int x1,y1,z1,x2,y2,z2;
int dx[]={0,1,0,-1,0,0};
int dy[]={1,0,-1,0,0,0};
int dz[]={0,0,0,0,1,-1};
int n,row,column;
struct Dungeon//地牢
{
int x,y,z;
int time;
friend bool operator < (Dungeon a,Dungeon b)
{
return a.time>b.time;
}
}; bool judge(int xt,int yt,int zt)
{
if(xt>row||xt<1||yt>column||yt<1||zt>n||zt<1) //越界
return 0;
if(map[zt][xt][yt]=='#')
return 0;
return 1;
}
int BFS()
{
priority_queue<Dungeon>q;
Dungeon pos,next;
pos.x=x1;
pos.y=y1;
pos.z=z1;
pos.time=0;
map[z1][x1][y1]='#';
q.push(pos);
while(!q.empty())
{
pos=q.top();
q.pop();
for(int i=0;i<6;++i)
{
next.x=pos.x+dx[i];
next.y=pos.y+dy[i];
next.z=pos.z+dz[i];
next.time=pos.time+1;
if(judge(next.x,next.y,next.z))
{
if(next.x==x2&&next.y==y2&&next.z==z2)
{
return next.time;
}
map[next.z][next.x][next.y]='#';
q.push(next);
}
}
}
return -1;
}
int main()
{ while(~scanf("%d%d%d",&n,&row,&column),n+row+column)
{
getchar();
for(int i=1;i<=n;++i)
{
for(int j=1;j<=row;++j)
{
for(int k=1;k<=column;++k)
{
scanf("%c",map[i][j]+k);
if(map[i][j][k]=='S')
{
z1=i,x1=j,y1=k;
}
else if(map[i][j][k]=='E')
{
z2=i,x2=j,y2=k;
}
}
getchar();
}
getchar();
}
int res;
res=BFS();
if(res==-1) printf("Trapped!\n");
else printf("Escaped in %d minute(s).\n",res);
}
return 0;
}

Dungeon Master ZOJ 1940【优先队列+广搜】的更多相关文章

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

  2. 【POJ - 2251】Dungeon Master (bfs+优先队列)

    Dungeon Master  Descriptions: You are trapped in a 3D dungeon and need to find the quickest way out! ...

  3. USACO Milk Routing /// 优先队列广搜

    题目大意: 在n个点 m条边的无向图中 需要运送X单位牛奶 每条边有隐患L和容量C 则这条边上花费时间为 L+X/C 求从点1到点n的最小花费 优先队列维护 L+X/C 最小 广搜到点n #inclu ...

  4. nyoj 1022 最少步数【优先队列+广搜】

    最少步数 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 这有一个迷宫,有0~8行和0~8列: 1,1,1,1,1,1,1,1,1 1,0,0,1,0,0,1,0,1 ...

  5. [题解](优先队列广搜)POJ_3635_Full Tank

    用二元组$(city,fuel)$即可记录所有状态,以当前花费为关键字优先队列,开数组记录直接做即可 有一个点在于每次不用枚举所有的加油数量,只需要加一即可,因为如果在加一升更优的话又会扩展出加更多油 ...

  6. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 A.Saving Tang Monk II(优先队列广搜)

    #include<bits/stdc++.h> using namespace std; ; ; char G[maxN][maxN]; ]; int n, m, sx, sy, ex, ...

  7. hrbust 1621 迷宫问题II 广搜

    题目链接:http://acm.hrbust.edu.cn/vj/index.php?/vj/index.php?c=&c=contest-contest&cid=134#proble ...

  8. hdu5025 状态压缩广搜

    题意:       悟空要救唐僧,中途有最多就把钥匙,和最多五条蛇,要求就得唐僧并且拿到所有种类的钥匙(两个1只拿一个就行),拿钥匙i之前必须拿到钥匙i-1,打蛇多花费一秒,问救出唐僧并且拿到所有种类 ...

  9. POJ 2251 Dungeon Master(广搜,三维,简单)

    题目 简单的3d广搜,做法类似与 hdu 的 胜利大逃亡 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<str ...

随机推荐

  1. 解决_CRT_SECURE_NO_WARNINGS 警告

    问题:我们在程序中使用fopen等CRT函数,就会出现一些警告信息,很烦人,如下: 1>e:/project/htt/ishow/functions.cpp(156) : warning C49 ...

  2. 几种常见的YUV格式--yuv422:yuv420【转】

    转自:http://blog.csdn.net/u012288815/article/details/51799477 关于yuv 格式 YUV 格式通常有两大类:打包(packed)格式和平面(pl ...

  3. 从jscript脚本混淆说起

    转载:http://www.freebuf.com/column/144897.html 脚本病毒是一个一直以来就存在,且长期活跃着的一种与PE病毒完全不同的一类病毒类型,其制作的门槛低.混淆加密方式 ...

  4. Python学习杂记_13_模块(一)_基础

    一.模块和模块调用 模块其实就是一个Python文件,模块的调用实际就是把这个Python文件从头到尾执行一遍. 如果是在相同路径下的调用: 1. 先导入整个模块,然后引用模块中的方法 import ...

  5. Android (Notification)消息推送机制

    从网上查询资料学习Android消息推送机制,效果图如下: 1.首先是布局文件代码 activity_main.xml <?xml version="1.0" encodin ...

  6. Android 之 AlarmManager(定时器) 的介绍和使用

    AlarmManager 包含的主要方法: // 取消已经注册的与参数匹配的定时器 void cancel(PendingIntent operation) //注册一个新的延迟定时器void set ...

  7. J.U.C并发框架源码阅读(十五)CopyOnWriteArrayList

    基于版本jdk1.7.0_80 java.util.concurrent.CopyOnWriteArrayList 代码如下 /* * Copyright (c) 2003, 2011, Oracle ...

  8. HDU 5649.DZY Loves Sorting-线段树+二分-当前第k个位置的数

    DZY Loves Sorting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Oth ...

  9. Python的网络编程[0] -> socket[0] -> socket 与 TCP / UDP

    Socket socket 简述 / socket Abstract 网络进程通信与 socket 网络中进程之间如何通信,首要解决的问题是如何唯一标识一个进程,否则通信无从谈起.在本地可以通过进程 ...

  10. MyBatis笔记:invalid bound statement (not found)

    maven项目在本地运行的时候没有问题,一旦把war包部署到测试机上就不能运行.查看了一下tomcat日志发现抛出这样的错误:invalid bound statement (not found),后 ...