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 ...
随机推荐
- 刷题总结——拦截导弹(ssoj)
题目: 题目背景 NOIP1999 提高组试题 题目描述 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都 ...
- P1736 创意吃鱼法 (动态规划)
题目描述 回到家中的猫猫把三桶鱼全部转移到了她那长方形大池子中,然后开始思考:到底要以何种方法吃鱼呢(猫猫就是这么可爱,吃鱼也要想好吃法 ^_*).她发现,把大池子视为01矩阵(0表示对应位置无鱼,1 ...
- Spoj-NPC2015A Eefun Guessing Words
Eefun Guessing Words Eefun is currently learning to read. His way of learning is unique, by trying ...
- Nearest Common Ancestors(poj 1330)
题意:给定一棵树,询问两个节点的最近公共祖先. 输入:第一行T,表示测试组数. 每组测试数据包含一个n,表示节点数目,下面n-1行是连接的边,最后一行是询问 输出:共T行,代表每组的测试结果 /* 倍 ...
- T1077 多源最短路 codevs
http://codevs.cn/problem/1077/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知n个点(n&l ...
- Oracle ORA-01033: ORACLE initialization or shutdown in progress
先说明,我出现此错误的原因是:我手动通过drop语句删除表空间,结果磁盘中文件还存在,然后我手动删除了文件,重启了oracle服务,再去连接oracle时就出现了这个错误. 网上也有“连接Oracle ...
- Linux下使用vi新建文件保存文件时遇到错误:E212: Can't open file for writing
出现E212: Can't open file for writing的问题是由于权限问题导致的,解决方法有以下思路: 1.使用root进行登录,然后再操作. 2.在使用命令时,前面加sudo. 3. ...
- Linux下使用nohup实现在后台运行程序(转)
相比上一篇http://www.cnblogs.com/EasonJim/p/6833417.html使用screen实现后台运行程序,各有各的好处,多一种选择吧. Linux下一般比如想让某个程序在 ...
- 更改Tomcat命令行窗体标题
在windows下启动多个tomcat时.不好区分哪个tomcat相应哪个服务,能够通过下面方法设置Tomcat命令行窗体的标题: 1.在%tomcat_home%\bin\catalina.b ...
- pandas入门指南
上一篇讲了numpy,除此之外,还有一个工具我们一定会使用,那就是pandas.如果说numpy中数据存储形式是列表的话,那么pandas中数据的存储形式更像是字典.为什么这么说呢?因为pandas中 ...