Dungeon Master(三维bfs)
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! 代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath> const int maxn=1e5+;
typedef long long ll;
char Map[][][];
int vis[][][];
struct node
{
int x,y,z;
int cnt;
};
using namespace std;
int sx,sy,sz;
int ex,ey,ez;
int dir[][]={{,,},{,,-},{-,,},{,,},{,,},{,-,}};
int s;
bool check(int x,int y,int z)
{
if((Map[z][x][y]=='.'||Map[z][x][y]=='E')&&vis[z][x][y]==)
{
return true;
}
else
{
return false;
}
}
bool bfs()
{
node start;
start.x=sx;
start.y=sy;
start.z=sz;
start.cnt=;
queue<node>q;
q.push(start);
vis[sz][sx][sy]=;
while(!q.empty())
{
node now=q.front();
q.pop();
//printf("%d %d %d\n",now.z,now.x,now.y);
if(now.z==ez&&now.x==ex&&now.y==ey)
{
s=now.cnt;
return true;
}
for(int t=;t<;t++)
{
node next;
next.x=now.x+dir[t][];
next.y=now.y+dir[t][];
next.z=now.z+dir[t][];
next.cnt=now.cnt+;
if(check(next.x,next.y,next.z))
{
vis[next.z][next.x][next.y]=;
q.push(next);
} }
}
return false;
}
int main()
{
int L,R,C;
while(scanf("%d%d%d",&L,&R,&C)!=EOF)
{
memset(vis,,sizeof(vis));
if(L==&&R==&&C==)
{
break;
}
s=;
for(int t=;t<L;t++)
{
for(int j=;j<R;j++)
{
scanf("%s",Map[t][j]);
}
}
for(int t=;t<L;t++)
{
for(int j=;j<R;j++)
{
for(int k=;k<C;k++)
{
if(Map[t][j][k]=='S')
{
sx=j;
sy=k;
sz=t;
}
if(Map[t][j][k]=='E')
{
ex=j;
ey=k;
ez=t;
}
}
}
} if(bfs())
printf("Escaped in %d minute(s).\n",s);
else
{
printf("Trapped!\n");
}
} return ;
}
Dungeon Master(三维bfs)的更多相关文章
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- POJ 2251 Dungeon Master (三维BFS)
题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ:Dungeon Master(三维bfs模板题)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16748 Accepted: 6522 D ...
- ZOJ 1940 Dungeon Master 三维BFS
Dungeon Master Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Desc ...
- UVa532 Dungeon Master 三维迷宫
学习点: scanf可以自动过滤空行 搜索时要先判断是否越界(L R C),再判断其他条件是否满足 bfs搜索时可以在入口处(push时)判断是否达到目标,也可以在出口处(pop时) #i ...
- 【POJ - 2251】Dungeon Master (bfs+优先队列)
Dungeon Master Descriptions: You are trapped in a 3D dungeon and need to find the quickest way out! ...
- 棋盘问题(DFS)& Dungeon Master (BFS)
1棋盘问题 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的 ...
- Dungeon Master (简单BFS)
Problem Description You are trapped in a 3D dungeon and need to find the quickest way out! The dunge ...
- POJ 2252 Dungeon Master 三维水bfs
题目: http://poj.org/problem?id=2251 #include <stdio.h> #include <string.h> #include <q ...
随机推荐
- sqlzoo刷题 SELECT from Nobel Tutorial
SELECT from Nobel Tutorial 1.Change the query shown so that it displays Nobel prizes for 1950. SELEC ...
- ubuntu apt-get 安装找不到包问题
1.首先 sudo gedit /etc/apt/sources.list 删除全部换成国内源 (推荐163) 2.考虑 ubuntu apt-get update失败 1.出现错误:E:Could ...
- 1. JDK基础说明
1. JDK基础说明 版本及新特性获取 作为技术人,关注新技术必不可少,那么最佳的途径...看下面. 在 Oracle Java 官方站点有这个非常好的引导地图 官方站点 https://docs.o ...
- DIFF算法浅析(三)在react中的实现
在虚拟dom中diff的实现. 分别从4个方面: DIFF抽象概念(概述.时间复杂性分析) 在Vue2中的实现(版本2.6.11.必要性.执行方式) 在React中的实现(版本16.13.1,必要性. ...
- NMS系列
NMS soft NMS softer NMS https://www.cnblogs.com/VincentLee/p/12579756.html
- 关于在Visual Studio 2019预览版中的用户体验和界面的变化
原文地址:https://blogs.msdn.microsoft.com/visualstudio/2018/11/12/a-preview-of-ux-and-ui-changes-in-visu ...
- C#设计模式之7-桥接模式
桥接模式(Bridge Pattern) 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/401 访问. 桥接模式属于结构 ...
- python3 - 常用的操作数据库
# 获取手机号数据表的中的数据 sql2 = 'SELECT shoujihao FROM shoujihao' self.cursor.execute(sql2) sjh_dates = self. ...
- 面试官最爱的 volatile 关键字,这些问题你都搞懂了没?
前言 volatile相关的知识点,在面试过程中,属于基础问题,是必须要掌握的知识点,如果回答不上来会严重扣分的哦. volatile关键字基本介绍 volatile可以看成是synchronized ...
- python 10 else EasyGui(转载)
else语句 if else 要么怎么样,要么不怎么样 while else 干完了能怎样,干不完就不怎样 (异常处理) else 没有问题,就干吧 try: int('a') except Valu ...