Dungeon Master ZOJ 1940【优先队列+广搜】
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?
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.
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!
3 4 5
S....
.###.
.##..
###.# #####
#####
##.##
##... #####
#####
#.###
####E 1 3 3
S##
#E#
### 0 0 0
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【优先队列+广搜】的更多相关文章
- 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 ...
- 【POJ - 2251】Dungeon Master (bfs+优先队列)
Dungeon Master Descriptions: You are trapped in a 3D dungeon and need to find the quickest way out! ...
- USACO Milk Routing /// 优先队列广搜
题目大意: 在n个点 m条边的无向图中 需要运送X单位牛奶 每条边有隐患L和容量C 则这条边上花费时间为 L+X/C 求从点1到点n的最小花费 优先队列维护 L+X/C 最小 广搜到点n #inclu ...
- 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 ...
- [题解](优先队列广搜)POJ_3635_Full Tank
用二元组$(city,fuel)$即可记录所有状态,以当前花费为关键字优先队列,开数组记录直接做即可 有一个点在于每次不用枚举所有的加油数量,只需要加一即可,因为如果在加一升更优的话又会扩展出加更多油 ...
- 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, ...
- hrbust 1621 迷宫问题II 广搜
题目链接:http://acm.hrbust.edu.cn/vj/index.php?/vj/index.php?c=&c=contest-contest&cid=134#proble ...
- hdu5025 状态压缩广搜
题意: 悟空要救唐僧,中途有最多就把钥匙,和最多五条蛇,要求就得唐僧并且拿到所有种类的钥匙(两个1只拿一个就行),拿钥匙i之前必须拿到钥匙i-1,打蛇多花费一秒,问救出唐僧并且拿到所有种类 ...
- POJ 2251 Dungeon Master(广搜,三维,简单)
题目 简单的3d广搜,做法类似与 hdu 的 胜利大逃亡 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<str ...
随机推荐
- 转 Join的实现原理及优化思路
前言 前面我们已经了解了MySQLQueryOptimizer的工作原理,学习了Query优化的基本原则和思路,理解了索引选择的技巧,这一节我们将围绕Query语句中使用非常频繁,且随时可能存在性能隐 ...
- Linux用户态定时器用法以及犯错总结【转】
转自:http://blog.csdn.net/csdn_logo/article/details/48525703 版权声明:本文为博主原创文章,欢迎转载,转载请注明出处,多谢合作. 采样的时候要用 ...
- MFC/C++/C中字符类型CString, int, string, char*之间的转换
1 CString,int,string,char*之间的转换 string 转 CString CString.format("%s", string.c_str()); cha ...
- mininet命令
官方文档:http://mininet.org/walkthrough/ 翻译的官方文档:https://segmentfault.com/a/1190000000669218 ovs-ofctl相关 ...
- "select一直返回0"的问题解决和总结
场景:一个简单的TCP 服务器,以实现UPNP的事件体系结构 我在linux平台下,创建一个TCP套接字,绑定到49156端口,向UPNP SERVER发一个subscribe订阅请求,超时时间设置为 ...
- 【linux高级程序设计】(第十五章)UDP网络编程应用 3
UDP组播通信 组播IP地址: D类IP地址 1110.********** 224.0.0.1 ~ 239.255.255.255 组播MAC地址:低23位,直接对应IP地址, 从右数第24位为 ...
- 手机APP测试技术-整体测试流程框架
一 手机APP测试基本思路: 测试计划--测试方案--测试用例--执行: 很多小公司都没有具体的需求,项目时间也比较紧,而且流程也不是很严谨,在这样的情况之下,作为测试的我们,该怎样去对项目进行用例 ...
- [BZOJ4568][SCOI2016]幸运数字(倍增LCA,点分治+线性基)
4568: [Scoi2016]幸运数字 Time Limit: 60 Sec Memory Limit: 256 MBSubmit: 2131 Solved: 865[Submit][Statu ...
- [JSOI2009] 有趣的游戏
1444: [Jsoi2009]有趣的游戏 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1800 Solved: 645[Submit][Statu ...
- 集合框架(01)Collection
1.集合:存储对象. 对象多了用集合存,数据多了用对象存 2.数组是固定长度,集合是不固定长度:数组是相同数据类型,集合是存储不同类型的对象 3 . 4.为什么会出现这么多的容器那,因为每一个容器对数 ...