POJ 3279 Dungeon Master
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 21242 | Accepted: 8265 |
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 注意xyz别弄混了
/* ***********************************************
Author :pk29
Created Time :2015/8/19 18:40:40
File Name :4.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10000+10
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
struct node{
int x,y,z;
int dist;
};
bool cmp(int a,int b){
return a>b;
}
int l,r,c;
char mp[][][];
int vis[][][];
int sx,sy,sz,ex,ey,ez;
int dir[][]={,,,,,,,,-,,,,-,,,,-,}; void bfs(){
node u,v;
u.x=sx,u.y=sy,u.z=sz, u.dist=;
queue<node>q;
q.push(u);
int mark=;
vis[u.x][u.y][u.z]=;
while(!q.empty()){
u=q.front(),q.pop();
if(u.x==ex&&u.y==ey&&u.z==ez){
mark=;printf("Escaped in %d minute(s).\n",u.dist);break;
}
for(int i=;i<;i++){
int nx=u.x+dir[i][];
int ny=u.y+dir[i][];
int nz=u.z+dir[i][];
if(!vis[nx][ny][nz]&&mp[nx][ny][nz]!='#'&&nx>=&&ny>=&&nz>=&&nx<=r&&ny<=c&&nz<=l){
v.x=nx,v.y=ny,v.z=nz;
v.dist=u.dist+;
q.push(v);
vis[nx][ny][nz]=;
}
}
}
if(!mark)printf("Trapped!\n");
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
while(cin>>l>>r>>c){
if(l==&&c==&&r==)break;
for(int i=;i<=l;i++)
for(int j=;j<=r;j++)
for(int k=;k<=c;k++){
cin>>mp[j][k][i];
if(mp[j][k][i]=='S')sx=j,sy=k,sz=i;
if(mp[j][k][i]=='E')ex=j,ey=k,ez=i;
}
cle(vis);
//cout<<sx<<sy<<sz<<endl;
//cout<<ex<<ey<<ez<<endl; bfs();
}
return ;
}
POJ 3279 Dungeon Master的更多相关文章
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- POJ 2251 Dungeon Master(地牢大师)
p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...
- 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 ...
- POJ.2251 Dungeon Master (三维BFS)
POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- BFS POJ 2251 Dungeon Master
题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...
- poj 2251 Dungeon Master
http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- POJ 2251 Dungeon Master (三维BFS)
题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ 2251 Dungeon Master(3D迷宫 bfs)
传送门 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 11 ...
- POJ 2251 Dungeon Master (非三维bfs)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 55224 Accepted: 20493 ...
随机推荐
- BZOJ2241 [SDOI2011]打地鼠 【模拟】
题目 打地鼠是这样的一个游戏:地面上有一些地鼠洞,地鼠们会不时从洞里探出头来很短时间后又缩回洞中.玩家的目标是在地鼠伸出头时,用锤子砸其头部,砸到的地鼠越多分数也就越高. 游戏中的锤子每次只能打一只地 ...
- CentOS7下安装Docker-Compose No module named 'requests.packages.urllib3'
在使用Docker的时候,有一个工具叫做 docker-compose,安装它的前提是要安装pip工具. 1.首先检查Linux有没有安装Python-pip包,直接执行 yum install p ...
- 洛谷P3143 [USACO16OPEN]钻石收藏家Diamond Collector
题目描述 Bessie the cow, always a fan of shiny objects, has taken up a hobby of mining diamonds in her s ...
- Influx kafka
http://www.opscoder.info/kafka-influxdb.html
- Neo4j 第七篇:模式(Pattern)
模式和模式匹配是Cypher的核心,使用模式来描述所需数据的形状,该模式使用属性图的结构来描述,通常使用小括号()表示节点,-->表示关系,-[]->表示关系和关系的类型,箭头表示关系的方 ...
- [Bzoj3675][Apio2014]序列分割(斜率优化)
3675: [Apio2014]序列分割 Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 4021 Solved: 1569[Submit][Stat ...
- IntelliJ IDEA简体中文专题教程
说明:应该是全网最全的中文教程了,包括一些常用的快捷键和配置等等.是的,我已经转IntelliJ IDEA了. 来自judasn的IntelliJ IDEA简体中文专题教程: https://gith ...
- amplab
https://github.com/amplab/SparkNet https://amplab.cs.berkeley.edu/
- ETCD 单机安装
由于测试的需要,有时需要搭建一个单机版的etcd 环境,为了方便以后搭建查看,现在对单机部署进行记录. 一.部署单机etcd 下载 指定版本的etcd下载地址 ftp://ftp.pbone.net/ ...
- 五步掌握Git的基本开发使用命令
第一步:设置全局变量: git config --global user.name "gang.li" git config --global user.email "l ...