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 ...
随机推荐
- Django models 常用字段类型
1.CharField字符串字段,存较短的字符串,长文本要用TextField.必须的参数:max_length 字符的最大长度2.TextField容量很大的文本字段.admin中用 <tex ...
- HEK_费用报表审核无审核权限,有些字段无法编辑的问题处理
Q:HEK_费用报表审核无审核权限,有些字段无法编辑的问题处理 A:设置AP员工->给AP员工分配审批权限->绑定员工和ERP账号 1.将审核人设置为AP员工 2.分配给员工审批权限 3. ...
- 控制台输入年龄,根据年龄输出不同的提示 ------if……else if ……else 语句
package com.zuoye.test; import java.util.Scanner; public class Nianling { public static void main(St ...
- eclipse中导入maven项目:org.apache.maven.archiver.MavenArchiver.getManifest(org.apache.maven.proje
org.codehaus.plexus.archiver.jar.Manifest.write(java.io.PrintWriter) 解决方法为:更新eclipse中的maven插件 1.help ...
- [Java]链表的打印,反转与删除
class Node{ public int value; public Node next=null; public Node(int value) { this.value=value; } }p ...
- socket主要函数介绍
1. 基本套接字函数(1)socket函数原型 socket(建立一个socket文件描述符) 所需头文件 #include <sys/types.h> #include <sy ...
- python爬虫07 | 有了 BeautifulSoup ,妈妈再也不用担心我的正则表达式了
我们上次做了 你的第一个爬虫,爬取当当网 Top 500 本五星好评书籍 有些朋友觉得 利用正则表达式去提取信息 太特么麻烦了 有没有什么别的方式 更方便过滤我们想要的内容啊 emmmm 你还别说 还 ...
- 【Codeforces 350B】Resort
[链接] 我是链接,点我呀:) [题意] [题解] 我们可以把原图的边都反向一下. 然后以每个休息点作为起点,进行dfs. 每次在扩展节点y的时候,要求这个点y必须只有一个出度,然后就能走多远就走多远 ...
- 第一次训练 密码:acmore
#include <cstdio> #include <cstring> #define M 100010 #define INF 0x7FFFFFFF #define Min ...
- 05springMVC数据格式化
数据格式化简介 内建的格式转换器 使用内建格式转换器示例 字段级别的解析/格式化 集成到Spring Web MVC环境 1 数据格式化简介 对属性对象的输入/输出进行格式化,其实是属于“类 ...