2015 UESTC 搜索专题A题 王之迷宫 三维bfs
A - 王之迷宫
Time Limit: 20 Sec Memory Limit: 256 MB
题目连接
http://acm.uestc.edu.cn/#/contest/show/61
Description
王被困在了一个3维的迷宫中,他很想逃离这个迷宫回去当学霸,你能帮助他么? 由于王很仁慈,他悄悄地告诉你,本题读入迷宫的每一行时,要用scanf("%s"...) ......
Input
L代表迷宫的高度,R和C分别代表每一层的行和列。
接下来是L个R×C的矩阵,矩阵包含4种字符(S,E,.,#),S代表王的初始位置,E代表出口,#代表障碍。.代表能通过的地方。
每一层之后有一个空行。
当L=R=C=0时,输入中断。
Output
如果可以逃离迷宫,按下列格式输出最短时间:
Escaped in x minute(s). (x表示逃离迷宫的最短时间, 走一步花费一昏钟)
否则,输出:
Trapped!
Sample Input
S....
.###.
.##..
###.#
#####
#####
##.##
##...
#####
#####
#.###
####E
1 3 3
S##
#E#
###
0 0 0
Sample Output
Trapped!
HINT
题意
题解:
啊,3维bfs搞一搞就好了
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
//**************************************************************************************
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
} string s[][];
int vis[][][];
int dx[]={,,,-,,};
int dy[]={,-,,,,};
int dz[]={,,,,,-};
struct node
{
int x,y,z;
ll t;
};
int l,r,c;
int main()
{
while(scanf("%d%d%d",&l,&r,&c)!=EOF)
{
memset(vis,,sizeof(vis));
if(l==&&r==&&c==)
break;
node st,ed;
for(int i=;i<l;i++)
for(int j=;j<r;j++)
cin>>s[i][j];
for(int i=;i<l;i++)
{
for(int j=;j<r;j++)
{
for(int k=;k<c;k++)
{
if(s[i][j][k]=='S')
{
st.x=i,st.y=j,st.z=k,st.t=;
vis[st.x][st.y][st.z]=;
}
}
}
}
int time=-;
queue<node> q;
q.push(st);
while(!q.empty())
{
node now=q.front();
q.pop();
if(s[now.x][now.y][now.z]=='E')
{
time=now.t;
break;
}
for(int i=;i<;i++)
{
node next=now;
next.x+=dx[i];
next.y+=dy[i];
next.z+=dz[i];
next.t++;
if(next.x<||next.x>=l)
continue;
if(next.y<||next.y>=r)
continue;
if(next.z<||next.z>=c)
continue;
if(s[next.x][next.y][next.z]=='#')
continue;
if(vis[next.x][next.y][next.z])
continue;
vis[next.x][next.y][next.z]=;
q.push(next);
}
}
if(time==-)
printf("Trapped!\n");
else
printf("Escaped in %d minute(s).\n",time);
}
}
2015 UESTC 搜索专题A题 王之迷宫 三维bfs的更多相关文章
- 2015 UESTC 搜索专题F题 Eight Puzzle 爆搜
Eight Puzzle Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 ...
- 2015 UESTC 搜索专题K题 秋实大哥の恋爱物语 kmp
秋实大哥の恋爱物语 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 De ...
- 2015 UESTC 搜索专题E题 吴队长征婚 爆搜
吴队长征婚 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Descri ...
- 2015 UESTC 搜索专题B题 邱老师降临小行星 记忆化搜索
邱老师降临小行星 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Des ...
- 2015 UESTC 搜索专题N题 韩爷的梦 hash
韩爷的梦 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Descrip ...
- 2015 UESTC 搜索专题M题 Palindromic String 马拉车算法
Palindromic String Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/s ...
- 2015 UESTC 搜索专题J题 全都是秋实大哥 kmp
全都是秋实大哥 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Desc ...
- 2015 UESTC 搜索专题D题 基爷的中位数 二分
基爷的中位数 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Descr ...
- 2015 UESTC 搜索专题C题 基爷与加法等式 爆搜DFS
基爷与加法等式 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Desc ...
随机推荐
- 转: oracle中schema指的是什么?
看来有的人还是对schema的真正含义不太理解,现在我再次整理了一下,希望对大家有所帮助. 我们先来看一下他们的定义:A schema is a collection of database obje ...
- [Leetcode] Longest Palindromic Subsequence
Longest Palindromic Subsequence 题解 题目来源:https://leetcode.com/problems/longest-palindromic-subsequenc ...
- 简约而不简单的Django
本文面向:有python基础,刚接触web框架的初学者. 环境:windows7 python3.5.1 pycharm专业版 Django 1.10版 pip3 一.Django简介 百度百 ...
- mysql视图学习总结(转)
一.使用视图的理由是什么?1.安全性.一般是这样做的:创建一个视图,定义好该视图所操作的数据.之后将用户权限与视图绑定.这样的方式是使用到 了一个特性:grant语句可以针对视图进行授予权限.2.查询 ...
- Python静态代码检查工具Flake8
简介 Flake8 是由Python官方发布的一款辅助检测Python代码是否规范的工具,相对于目前热度比较高的Pylint来说,Flake8检查规则灵活,支持集成额外插件,扩展性强.Flake8是对 ...
- webStorage,离线缓存
一.webStorage 1.目标 1.了解cookie的不足之处,引入webstorage的概念 2.学习并且掌握webstorage有哪两种 3.学习并且掌握sessionStorag ...
- (转载)Linux入门:操作目录和文件的命令
PATH 每个用户的PATH都是不一样的: PATH中不包含“当前目录”: (1)echo $PATH:显示PATH环境变量: (2)PATH = "$PATH":/home/ ...
- [loj6038]「雅礼集训 2017 Day5」远行 lct+并查集
给你 n 个点,支持 m 次操作,每次为以下两种:连一条边,保证连完后是一棵树/森林:询问一个点能到达的最远的点与该点的距离.强制在线. n≤3×10^5 n≤3×10^5 ,m≤5×10^5 m≤5 ...
- 【C#日期系列(一)】--C#获取某月第一天0分0秒以及最后一天59分59秒
工作中可能会遇到很多不常见的需求,比如这次需要获取某个月的第一天和最后一天 #region 取得某月的第一天0分0秒 /// <summary> /// 取得某月的第一天0分0秒 /// ...
- 【LOJ】 #2009. 「SCOI2015」小凸玩密室
题解 神仙dp啊QAQ 我们发现我们需要枚举一个起点,遍历完它所有的儿子然后向上爬 设\(f[i][j]\)表示第i个点的子树全部处理完之后到达i深度为j的祖先的兄弟处 我们只需要对叶子节点和只有一个 ...