(广搜)Dungeon Master -- poj -- 2251
链接:
http://poj.org/problem?id=2251
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 21370 | Accepted: 8299 |
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!
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue> using namespace std; #define N 35 struct node
{
int x, y, z, step;
}; char Map[N][N][N];
node e;
int L, R, C;
int dir[][]={{,,-},{,,},{,-,},{,,},{-,,},{,,}}; bool Judge(node s)
{
return s.x>= && s.x<L && s.y>= && s.y<R && s.z>= && s.z<C && Map[s.x][s.y][s.z]!='#';
} int BFS(node s)
{
node p;
queue<node>Q;
Q.push(s); while(Q.size())
{
s = Q.front(), Q.pop(); if(s.x==e.x && s.y==e.y && s.z==e.z) return s.step; for(int i=; i<; i++)
{
p.x = s.x + dir[i][];
p.y = s.y + dir[i][];
p.z = s.z + dir[i][];
p.step = s.step + ; if(Judge(p))
{
Q.push(p);
Map[p.x][p.y][p.z] = '#';
}
}
}
return -;
} int main()
{
while(scanf("%d%d%d", &L, &R, &C), L+R+C)
{
node s; memset(Map, , sizeof(Map)); for(int i=; i<L; i++)
for(int j=; j<R; j++)
{
scanf("%s", Map[i][j]);
for(int k=; k<C; k++)
{
if(Map[i][j][k]=='S')
s.x=i, s.y=j, s.z=k, s.step=;
if(Map[i][j][k]=='E')
e.x=i, e.y = j, e.z=k;
}
} int ans = BFS(s); if(ans==-)
printf("Trapped!\n");
else
printf("Escaped in %d minute(s).\n", ans);
} return ;
}
(广搜)Dungeon Master -- poj -- 2251的更多相关文章
- Dungeon Master poj 2251 dfs
Language: Default Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16855 ...
- Dungeon Master POJ - 2251 (搜索)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 48605 Accepted: 18339 ...
- Dungeon Master POJ - 2251(bfs)
对于3维的,可以用结构体来储存,详细见下列代码. 样例可以过,不过能不能ac还不知道,疑似poj炸了, #include<iostream> #include<cstdio> ...
- Dungeon Master POJ - 2251 [kuangbin带你飞]专题一 简单搜索
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- B - Dungeon Master POJ - 2251
//纯bfs #include <iostream> #include <algorithm> #include <cstring> #include <cs ...
- kuangbin专题 专题一 简单搜索 Dungeon Master POJ - 2251
题目链接:https://vjudge.net/problem/POJ-2251 题意:简单的三维地图 思路:直接上代码... #include <iostream> #include & ...
- 广搜+打表 POJ 1426 Find The Multiple
POJ 1426 Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25734 Ac ...
- 广搜+输出路径 POJ 3414 Pots
POJ 3414 Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13547 Accepted: 5718 ...
- POJ 2251 Dungeon Master(广搜,三维,简单)
题目 简单的3d广搜,做法类似与 hdu 的 胜利大逃亡 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<str ...
随机推荐
- LR-IE录制设置
ie浏览器去掉启用第三方浏览器扩展,路径. ie浏览器-工具-internet选项-高级,在列表中找到“启用第三方浏览器扩展” 把钩去掉 . 启动loadrunner11,按键盘F4,在brows ...
- 关于ROS的MANGLE和ip route-rules-lookup的关系和区别
mangle打出来的mark routing的优先级和lookup打出来的优先级是一样的.(你可以这么理解,lookup根据目的地址打出来的标签,其实跟在ip firewall-mangle打出来的是 ...
- Ruby中数组的遍历
转自:http://www.jianshu.com/p/8de9b60f9350 Ruby中有几个常用的遍历数组的方法,本人经常容易搞混.这里列出来总结一下. each: 从数组中取出一个元素,作为某 ...
- Asp.net 页面传值的方法
ASP.NET页面传值的方法 From:Refresh-air 在面试的时候,经常会遇到这样的问题,其实我们会对其中的几种方法比较熟悉,因为项目中经常使用.但是要全面的回答ASP.NET中页面传值的方 ...
- 6.1课堂笔记—DML(数据操作语言),DQL查询语句
一.DML(数据操作语言) InnoDB MyISAM 支持事务 不支持事务 不支持全文索引 支持全文索引 支持外键约束 不支持 命令查看默认存储引擎 show variables like '%st ...
- Centos编译Redis4.0.9源码过程记录
mkdir /home/redis cd /home/redis 下载源码 wget https://codeload.github.com/antirez/redis/tar/4.0.9 解压源码包 ...
- 概率分布之间的距离度量以及python实现
1. 欧氏距离(Euclidean Distance) 欧氏距离是最易于理解的一种距离计算方法,源自欧氏空间中两点间的距离公式.(1)二维平面上两点a(x1,y1)与b(x2,y2)间的欧 ...
- WeakHashMap, NOT A CACHE
Overview Base Map的实现 基于WeakReference的Entity实现 基于Reference和ReferenceQueue实现 它的弱引用是键,而不是值 它的key会被全自动回收 ...
- iOS开源项目:AFNetworking----写得非常好
https://github.com/AFNetworking/AFNetworking 与asi-http-request功能类似的网络库,不过是基于NSURLConnection 和 NSOper ...
- Python基础语法习题二
习题: 1.请用代码实现:利用下划线将列表的每一个元素拼接成字符串,li=['alex', 'eric', 'rain'] 2.查找列表中元素,移除每个元素的空格,并查找以a或A开头并且以c结尾的所有 ...