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 ...
随机推荐
- Win7如何改变用户文件夹位置
现在装WIN7后第一件就是改变用户账户文件夹位置..因为里面存着一些软件的设定和信息等..不必要每次装后都手动改一次.. 已前用优化大师改.太麻烦.也不稳定有时有些目录不能完全改过来.. 通过命令mk ...
- 怎样实现广度优先遍历(BFS)
BFS过程: 一:訪问顶点V,并标记V为已经訪问 二:顶点V入队列 三:假设队列非空.进行运行,否则算法结束 四:出队列取得对头顶点u,假设顶点未被訪问,就訪问该顶点,并标记该顶点为已经訪问 五:查找 ...
- Python Socket API 笔记
将上节中的C#该成Python版的容易程度大大超出了我的意料之外.从来没有发现,仅仅用灰尘简单的几句话就实现了该程序的主要功能,可见python的简易和强大之处.这里先对SocketAPI 做一下总结 ...
- JavaScriptl 类数组转换为数组
slice和Array.form方法,具体见示例代码: <!DOCTYPE html> <html lang="zh"> <head> < ...
- linux 终端分屏命令vsp(转)
比如:某文件夹下有文件:vector.cc, substr.cc 1.使用vim命令打开任意一个文件:vim vector.cc打开第一个文件.如下图所示: 2.按:"Esc"键 ...
- CentOS 6.3下部署LVS(NAT)+keepalived实现高性能高可用负载均衡(转)
一.简介 VS/NAT原理图: 二.系统环境 实验拓扑: 系统平台:CentOS 6.3 Kernel:2.6.32-279.el6.i686 LVS版本:ipvsadm-1.26 keepalive ...
- centos下nginx启动脚本和chkconfig管理
在安装完nginx后,重新启动需要“kill -HUP nginx进程编号”来进行重新加载,显然十分不方便.如果能像apache一样,直接通过脚本进行管理就方便多了. nginx官方早就想好了,也提供 ...
- 从第三方Launcher授权启动指定APP的设计与实现
Case 背景: Case要求从第三方Launcher中首次启动指定的应用程序时.弹出对话框提示用户进行授权启动,若用户未授权,则在下次再次启动该应用时依旧弹出对话框提示用户进行授权.直到用户相应用进 ...
- QT学习二:工具栏
QT 的工具栏提供 Dock 功能.文字/图标显示排列的功能. void MainWindow::createToolBar(void) { QToolBar *toolBar = new QToo ...
- kafka consumer assign 和 subscribe模式差异分析
转载请注明原创地址:http://www.cnblogs.com/dongxiao-yang/p/7200971.html 最近需要研究flink-connector-kafka的消费行为,发现fli ...