暑假集训(1)第三弹 -----Dungeon Master(Poj2251)
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! 问题分析:依旧是简单bfs,但是要用三维数组储存地图,但是有6个分支,用数组来储存方向可以让程序更简洁。
#include "iostream"
#include "queue"
using namespace std;
char maze[][][];
int v[][]={,,-,,,,,-,,,,,-,,,,,};
int L,R,C;
struct escaper
{
int i;
int j;
int k;
int time;
};
escaper fir;
void mbegin()
{
for (int i=;i<=L+;i++)
for (int j=;j<=R+;j++)
for (int k=;k<=C+;k++)
if (i*j*k == || i == L+ || j==R+ || k==C+)
maze[i][j][k] = '#';
else
{
cin>>maze[i][j][k];
if (maze[i][j][k] == 'S')
{
fir.i = i;
fir.j = j;
fir.k = k;
}
}
}
void bfs()
{
queue <escaper> p;
escaper sec;
fir.time=;
p.push(fir);
while (!p.empty())
{
sec = p.front();
p.pop();
for (int i=;i<;i++)
{
fir.i = sec.i+v[i][];
fir.j = sec.j+v[i][];
fir.k = sec.k+v[i][];
if (maze[fir.i][fir.j][fir.k] != '#')
{
fir.time = sec.time+;
if (maze[fir.i][fir.j][fir.k] == 'E')
{
cout<<"Escaped in "<<fir.time<<" minute(s)."<<endl;
return;
}
maze[fir.i][fir.j][fir.k] = '#';
p.push(fir);
}
}
}
cout<<"Trapped!"<<endl;
}
int main()
{
while (cin>>L>>R>>C && L && R && C)
{
mbegin();
bfs();
}
return ;
}
暑假集训(1)第三弹 -----Dungeon Master(Poj2251)的更多相关文章
- 暑假集训(2)第三弹 ----- 食物链(poj1182)
C - 食物链 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:10000KB 64bit ...
- 暑假集训(4)第三弹 -----递推(Hdu1799)
问题描述:还记得正在努力脱团的小A吗? 他曾经最亲密的战友,趁他绘制贤者法阵期间,暗中设下鬼打墙将小A 围困,并准备破坏小A正在绘制的法阵.小A非常着急.想阻止他的行动.而要阻止他,必须先破解鬼打墙. ...
- 暑假集训(3)第三弹 -----Til the Cows Come Home(Poj2387)
题意梗概:据说母牛在产奶的时候,因为奶量太充足,希望有人帮它挤奶,它回家就很快.我们便能喝到鲜美的 牛奶,不过,贫奶季节却大不相同,它会懒洋洋的在大草原上晃来晃去的晒太阳,而不会想到马上回家,这可不 ...
- bfs—Dungeon Master—poj2251
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 32228 Accepted: 12378 ...
- 暑假集训(4)第六弹——— 组合(poj1067)
题意概括:上一次,你成功甩掉了fff机械兵.不过,你们也浪费了相当多的时间.fff团已经将你们团团包围,并且逐步 逼近你们的所在地.面对如此危机,你不由得悲观地想:难道这acm之路就要从此中断?虽然走 ...
- 暑假集训(2)第七弹 -----今年暑假不AC(hdu2037)
J - 今年暑假不AC Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB 64 ...
- 暑假集训(4)第五弹——— 数论(hdu1222)
题意概括:那天以后,你好说歹说,都快炼成三寸不烂之舍之际,小A总算不在摆着死人脸,鼓着死鱼眼.有了点恢复的征兆.可孟子这家伙说的话还是有点道理,那什么天将降....额,总之,由于贤者法阵未完成,而小A ...
- 暑假集训(4)第八弹——— 组合(hdu1524)
题意概括:你已经赢得两局,最后一局是N个棋子往后移动,最后一个无法移动的玩家失败. 题目分析:有向无环图sg值游戏,尼姆游戏的抽象表达.得到每个棋子的sg值之后,把他们异或起来,考察异或值是否为0. ...
- 暑假集训(4)第七弹——— 组合(hdu1850)
题意概括:你赢得了第一局.魔鬼给出的第二局是,如果有N堆牌,先手的人有几种可能胜利. 问题分析:尼姆游戏,先得到n堆牌的数量异或和,再将异或和与每一个牌组的数量异或,如果结果小于原牌组数量 则可能++ ...
随机推荐
- HW4.37
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- 小波变换和motion信号处理(一)(转)
写的太好,不得不转:http://www.kunli.info/2011/02/15/fourier-wavelet-motion-signal-1/ 这是<小波变换和motion信号处理> ...
- wave文件(*.wav)格式、PCM数据格式, goldwave 可以播放pcm raw audio
1. 音频简介 经常见到这样的描述: 44100HZ 16bit stereo 或者 22050HZ 8bit mono 等等. 44100HZ 16bit stereo: 每秒钟有 44100 次采 ...
- hdoj 2568 前进
前进 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- HDU 2554 N对数的排列问题
LINK:HDU 2554 这是昨天晚上小练里面比较有趣的一道题~我在做的时候思路错了,以为数字的排列会有规律,结果后面发现就算有也很难找......╮(╯▽╰)╭ 看了网上的题解,有一种恍然大悟的感 ...
- 编译Android4.3内核源代码
--------------------------------------------------------------------------------------------------- ...
- Dom4j写XML
package com; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.I ...
- 谈谈Javascript线程
其实,大家都知道Javascript的语言执行环境是单线程的,浏览器无论在什么时候都有且只有一个线程在运行Javascript程序.那Ajax发送异步请求怎么解释,setTimeout/s ...
- 嵌入式Linux-linux连接脚本
嵌入式Linux-linux连接脚本 介绍 每一个链接过程都由链接脚本(linker script, 一般以lds作为文件的后缀名)控制. 链接脚本主要用于规定如何把输入文件内的section放入输出 ...
- 第九篇:web之前端之web上传文件的方式
前端之web上传文件的方式 前端之web上传文件的方式 本节内容 web上传文件方式介绍 form上传文件 原生js实现ajax上传文件 jquery实现ajax上传文件 form+iframe构 ...