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 ...
随机推荐
- SQLCMD Mode: give it one more chance
From : http://sqlblog.com/blogs/maria_zakourdaev/archive/2012/05/11/sqlcmd-mode-give-it-one-more-cha ...
- Server 非阻塞
import socket import select import Queue port =500 host = "" sock = socket.socket(socket.A ...
- <十>读<<大话设计模式>>之观察者模式
观察者模式也是比較简单的一种模式,可能从名字上理解无法明确,但真正理解其含义之后就非常easy了,说实话在自己来发的项目中自己也用到过.仅仅只是不知道它叫观察者罢了,仅仅要懂面向对象的对继承多态理解非 ...
- Django——META内部类选项
Django 模型类的Meta是一个内部类,它用于定义一些Django模型类的行为特性.以下对此作一总结: abstract 这个属性是定义当前的模型类是不是一个抽象类.所谓抽象类是不会对应 ...
- Apache代理80端口
找到Apache下的conf\extra\httpd-vhosts.conf文件 新增以下内容于合适位置 ↓表示80端口 <VirtualHost *:80> ServerAdmin * ...
- 【MyBatis学习10】高级映射之多对多查询
本文来总结一下mybatis中的多对多映射,从第8节的文章中可以看出,用户表和商品表示多对多关系,它们两的多对多是通过订单项和订单明细这两张表所关联起来的,那么这一节主要来总结一下用户表和商品表之间的 ...
- 【MyBatis学习02】走进MyBatis的世界
mybatis是个持久层的框架,用来执行数据库操作的,无外乎增删改查,上一节对mybatis有了宏观上的了解后,这一篇博客主要通过一个小示例来入门mybatis,先看一下要写的示例需求: 根据用户id ...
- Linux 下 grep 命令常用方法简介
1.从单个文件中搜索指定的字符串: $ grep "literal-string" filename 该命令会输出字符串在文件中所在行的内容,如果字符串没有空格,则可以不加双引号. ...
- 在CentOS 6.3中安装拼音输入法
安装:su root yum install "@Chinese Support" // 安装中文输入法 exit安装完毕,在“系统-->首选项”会看到“输入法”一 ...
- web info
http://blog.csdn.net/qq_24473141/article/details/51363662 http://blog.sina.com.cn/s/blog_8e392fc2010 ...