C - Dungeon Master
C - Dungeon Master
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
Is an escape possible? If yes, how long will it take?
Input
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
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! //用dfs做的,就是在试探的时候多试探一次上下位置的时候就行。
#include <iostream>
#include <queue>
#include <string.h>
using namespace std; struct point
{
int x,y,h;
int step;
};
point star,end; char map [][][];
bool way [][][];
int h,x,y; void read_map()//读地图
{
for (int i=;i<=h;i++)
{
for (int j=;j<=x;j++)
{
for (int k=;k<=y;k++)
{
cin>>map[i][j][k];
if (map[i][j][k]=='S')
{
star.h=i;
star.x=j;
star.y=k;
star.step=;
}
if (map[i][j][k]=='E')
{
end.h=i;
end.x=j;
end.y=k; }
}
}
}
} int check(point t)//检查是否能走
{ if ( t.x>= && t.x<=x && t.y>= && t.y<=y && t.h>= && t.h<=h && way[t.h][t.x][t.y]== )
{
if ( map[t.h][t.x][t.y]!='#')
{
return ;
}
}
return ;
} int bfs()
{
point now,next;
int min=-; queue<point> Q;
Q.push(star);
way[star.h][star.x][star.y]=; while (!Q.empty())
{
now=Q.front();
Q.pop();
if (now.x==end.x&&now.y==end.y&&now.h==end.h)
{
min=now.step;
break;
} next.x=now.x+;
next.y=now.y;
next.h=now.h;
next.step=now.step+;
if (check(next)){ Q.push(next); way[next.h][next.x][next.y]=;} next.x=now.x;
next.y=now.y-;
next.h=now.h;
next.step=now.step+;
if (check(next)){ Q.push(next); way[next.h][next.x][next.y]=;} next.x=now.x-;
next.y=now.y;
next.h=now.h;
next.step=now.step+;
if (check(next)){ Q.push(next); way[next.h][next.x][next.y]=;} next.x=now.x;
next.y=now.y+;
next.h=now.h;
next.step=now.step+;
if (check(next)){ Q.push(next); way[next.h][next.x][next.y]=;} next.x=now.x;
next.y=now.y;
next.h=now.h+;
next.step=now.step+;
if (check(next)){ Q.push(next); way[next.h][next.x][next.y]=;} next.x=now.x;
next.y=now.y;
next.h=now.h-;
next.step=now.step+;
if (check(next)){ Q.push(next); way[next.h][next.x][next.y]=;}
}
return min; } int main()
{
int all;
while (cin>>h>>x>>y)
{
memset(way,,sizeof(way));
if (h==&&x==&&y==) break;
read_map();
all=bfs();
if (all==-)
cout<<"Trapped!"<<endl;
else
cout<<"Escaped in "<<all<<" minute(s)."<<endl;
}
return ;
}
C - Dungeon Master的更多相关文章
- 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 ...
- 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 ...
随机推荐
- Vue 过滤器filters
1.示例代码 采用vue单文件组件,使用moment插件格式化日期 <template> <div> <h1>{{date | dateFormat}}</h ...
- Android 4.4 Kitkat Phone工作流程浅析(七)__来电(MT)响铃流程
本文来自http://blog.csdn.net/yihongyuelan 转载请务必注明出处 本文代码以MTK平台Android 4.4为分析对象,与Google原生AOSP有些许差异,请读者知悉. ...
- 51单片机 | SPI协议与应用实例
———————————————————————————————————————————— SPI总线 - - - - - - - - - - - - - - - - - - - - - - - - - ...
- JSON——Java中的使用
1. 构建JSON方法(数据——>JSON) 这里使用Maven构建项目 在pom.xml中添加如下依赖 <dependency> <groupId>org.json&l ...
- iOS开发-Swift获取手机设备信息(UIDevice)
使用UiDevice获取设备信息 获取设备名称 let name = UIDevice.currentDevice().name 获取设备系统名称 let systemName = UIDevice. ...
- linux归档压缩命令
1.tar tar -cf output.tar file1.txt file2.txt .. tar -rvf output.tar fl ...
- ios 自动布局水平跟垂直居中
[view addConstraint:[NSLayoutConstraint constraintWithItem:segment attribute:NSLayoutAttributeCenter ...
- 在iis6里使用没有扩展名的mvc
这2天mvc第二个预览终于出来了.赶紧拿过来测试.在装了3.5的虚拟主机上运行正常.应该已经可以到能正常使用的阶段了.不过我前面一篇翻译的文章中说到,如果使用的是iis6的话就只能忍气吞声的使用带扩展 ...
- Session值的存储与删除
private static void SetSession<T>(string key, T val) { HttpContext.Current.Session[key] = (T)v ...
- 【Android】 给我一个Path,还你一个酷炫动画
本篇文章已授权微信公众号 hongyangAndroid (鸿洋)独家公布 转载请标明出处: http://blog.csdn.net/zxt0601/article/details/53040506 ...