暑假集训(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堆牌的数量异或和,再将异或和与每一个牌组的数量异或,如果结果小于原牌组数量 则可能++ ...
随机推荐
- Codeforces126B - Password(KMP)
题目大意 给定一个字符串S,要求你找到一个最长的子串,它既是S的前缀,也是S的后缀,并且在S的内部也出现过(非端点) 题解 KMP的失配函数f[i]的非零值就是前i个字符的一个最长前缀且也是后缀的字符 ...
- ubuntu下使用脚本交叉编译windows下使用的ffmpeg + X264
这里主要是补充一些遇到的问题和解决方法. 2013-06 下旬 由于项目需要,重新编译ffmpeg+264+其他. 这里使用的环境Ubuntu 13.04,脚本依然是cross_compile_ffm ...
- jquery ajax return值不能取得的解决方案
jQuery ajax - ajax() 方法 http://www.w3school.com.cn/jquery/ajax_ajax.asp http://www.cnblogs.com/fqw19 ...
- console.read()读入的内容
今天写的特别简单的代码,大体是一个模式选择,从控制台读入一个数,然后做出相应的选择. 代码如下: using System; using System.Collections.Generic; usi ...
- ScheduledExecutorFactoryBean忽略异常继续执行
ScheduledExecutorFactoryBean忽略异常继续执行 程序中有一个定时任务,每10分钟把满足条件的任务从一个表迁移到另一张表,程序启动的时候数据库异常了一段时间,之后数据库恢复了. ...
- Android学习之 博客专栏 与 资料
android | Android Developers Android学习系列 - 谦虚的天下 - 博客园 android基础 - 生如夏花之灿烂 - 博客园 Android开发 - 皓月繁星 - ...
- JS----构造函数与原型prototype 区别
构造函数方法很好用,但是存在一个浪费内存 通过原型法分配的函数是所有对象共享的.通过原型法分配的属性是独立.-----如果你不修改属性,他们是共享 如果我们希望所有的对象使用同一一个函数,最好使用原型 ...
- Linux为Tomecat指定JDK
在搭建Jenkin+Sonar集成时,由于系统环境配置了jdk1.7,但是jenkins在安装sonar的插件时,需要jdk1.8.,所以需要在Tomcat指定jdk1.8. (1)暂停Tomcat ...
- 如何生成Dump文件
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:如何生成Dump文件.
- Eclipse选择rt.jar的源代码的位置
1.点 “window”-> "Preferences" -> "Java" -> "Installed JRES" 2. ...