Dungeon Master hdoj
Dungeon Master
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 46 Accepted Submission(s) : 16
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!
#include<stdio.h>
#include<queue>
#include<string.h>
using namespace std;
char map[31][31][31];
int vis[31][31][31];
int dx[6]={1,0,-1,0,0,0};
int dy[6]={0,0,0,1,0,-1};
int dz[6]={0,1,0,0,-1,0};
int x,y,z,ex,ey,ez,m,n,l;
struct node
{
int x,y,z;
int step;
friend bool operator< (node n1,node n2)
{
return n1.step>n2.step;
}
}p,temp;
bool judge(node r)
{
if(r.x<0||r.x>=m||r.y<0||r.y>=n||r.z<0||r.z>=l)
return true;
if(vis[r.x][r.y][r.z]||map[r.x][r.y][r.z]=='#')
return true;
return false;
}
int bfs()
{
memset(vis,0,sizeof(vis));
priority_queue<node>q;
while(!q.empty()) q.pop();
p.x=x;
p.y=y;
p.z=z;
p.step=0;
q.push(p);
vis[x][y][z]=1;
while(!q.empty())
{
p=q.top();
q.pop();
if(p.x==ex&&p.y==ey&&p.z==ez)
{
return p.step;
}
for(int i=0;i<6;i++)
{
temp=p;
temp.x=p.x+dx[i];
temp.y=p.y+dy[i];
temp.z=p.z+dz[i];
if(judge(temp))
continue;
vis[temp.x][temp.y][temp.z]=1;
temp.step=p.step+1;
q.push(temp);
}
}
return 0;
}
int main()
{
while(scanf("%d%d%d",&m,&n,&l)!=EOF)
{
memset(map,'\0',sizeof(map));
getchar();
if(m+n+l==0)
break;
int i,j,k;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
scanf("%s",&map[i][j]);
for(k=0;k<l;k++)
{ if(map[i][j][k]=='S')
{
x=i;y=j;z=k;
}
if(map[i][j][k]=='E')
{
ex=i;ey=j;ez=k;
}
}
//getchar();
}
/*for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
for(k=0;k<l;k++)
printf("%c",map[i][j][k]);
printf("\n");
}*/
//printf("%d %d %d %d %d% d",x,y,z,ex,ey,ez);
int ans=bfs();
if(ans!=0)
printf("Escaped in %d minute(s).\n",ans);
else
printf("Trapped!\n");
}
return 0;
}
Dungeon Master hdoj的更多相关文章
- POJ 2251 Dungeon Master(3D迷宫 bfs)
传送门 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 11 ...
- poj 2251 Dungeon Master
http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- Dungeon Master 分类: 搜索 POJ 2015-08-09 14:25 4人阅读 评论(0) 收藏
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20995 Accepted: 8150 Descr ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- UVa532 Dungeon Master 三维迷宫
学习点: scanf可以自动过滤空行 搜索时要先判断是否越界(L R C),再判断其他条件是否满足 bfs搜索时可以在入口处(push时)判断是否达到目标,也可以在出口处(pop时) #i ...
- Dungeon Master poj 2251 dfs
Language: Default Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16855 ...
- POJ 2251 Dungeon Master(地牢大师)
p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...
- BFS POJ2251 Dungeon Master
B - Dungeon Master Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- POJ 2251 Dungeon Master (非三维bfs)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 55224 Accepted: 20493 ...
随机推荐
- 易企CMS仿站标签说明
头部标签: 每个页面都必须加的三大标签(将标签放入header.tpl里面,这样只需在每个模板中调用header.tpl即可): <title>{$seotitle}_{$sitename ...
- React-Router ---withRouter
import React from 'react' import { withRouter } from 'react-router' const Hello = (props) => { re ...
- CentOS6.9下NFS配置说明
NFS是Network File System的缩写,即网络文件系统.它的主要功能是通过网络(一般是局域网)让不同的主机系统之间可以共享文件或目录.NFS客户端可以通过挂载(mount)的方式将NFS ...
- 【Leetcode】【简单】【682棒球比赛】【JavaScript】
题目 682. 棒球比赛 你现在是棒球比赛记录员.给定一个字符串列表,每个字符串可以是以下四种类型之一:1.整数(一轮的得分):直接表示您在本轮中获得的积分数.2. "+"(一轮的 ...
- 51nod1081 子段求和
给出一个长度为N的数组,进行Q次查询,查询从第i个元素开始长度为l的子段所有元素之和. 例如,1 3 7 9 -1,查询第2个元素开始长度为3的子段和,1 {3 7 9} -1.3 + 7 + 9 = ...
- svn版本库更新后自动同步到www
注意:www目录一定要用SVN服务器 checkout出Repositories的代码 步骤: (1)新建www根目录 mkdir -p /data/www/lehuo (2)在www根目录下检出(c ...
- jQuery升级踩坑之路
1.使用了被废弃的jQuery.browser属性 jQuery 从 1.9 版开始,移除了 $.browser 和 $.browser.version , 取而代之的是 $.support . 在更 ...
- PHP统计当前在线用户数实例
HTML 我们在页面上放置一个显示当前在线人数的div#total以及一个用于展示访客地区分布的列表#onlinelist,默认我们在列表中放置一张与加载动画图片,后面我们用jQuery控制当鼠标滑向 ...
- BZOJ 1500 Luogu P2042 [NOI2005] 维护数列 (Splay)
手动博客搬家: 本文发表于20180825 00:34:49, 原地址https://blog.csdn.net/suncongbo/article/details/82027387 题目链接: (l ...
- elasticsearch 文档阅读笔记(三)
文档 elasticsearch是通过document的形式存储数据的,个人理解文档就是一条数据一个对象 我们添加索引文档中不仅包含了数据还包含了元数据 比如我们为一个数据添加索引 文档中不仅有jso ...