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 ...
随机推荐
- 【转载】WebDriver(C#)之十点使用心得
使用Selenium WebDriver驱动浏览器测试的过程中多多少少会遇到一些折腾人的问题,总结了一部分,做下分享. 一.隐藏元素处理(element not visible) 使用WebDrive ...
- Loadrunner脚本学习总结
1.1 web脚本录制选择Web(HTTP/HTML)协议: 注意录制脚本前选择如下协议: 1.2 脚本如果需要使用如下函数: web_reg_save_param.web_fin ...
- MAC 文件被锁定
从windows拷贝到MAC的文件,有时候会被锁定.右键-简介-已锁定也是灰色的,无法取消: xattr -l 文件名 xattr -d com.apple.FinderInfo 文件名
- 【转载】python import和from import
import和from import都是将其他模块导入当前模块中. 刚开始一直以为import和from import唯一的区别,就是from import可以少写一些模块名.虽然from XX im ...
- golang之结构体和方法
结构体的定义 结构体是将零个或者多个任意类型的命令变量组合在一起的聚合数据类型.每个变量都叫做结构体的成员. 其实简单理解,Go语言的结构体struct和其他语言的类class有相等的地位,但是GO语 ...
- spring boot 使用不同的profile来加载不同的配置文件
在开发过程之中,经常需要在开发和测试环境中进行互相切换,当切换的同时需要加载相应的配置文件,因此要经常 性的对配置文件进行相应的修改,长此以往感到十分痛苦.如果能针对开发和测试环境分别建两个不同的配置 ...
- loadrunner乱码问题解决办法
7.LoadRunner回放脚本时,在浏览器显示的中文是乱码 最近,遇到了好多乱码的问题,解决了一些,还有最后一个乱码,能想到的各种办法都试过了,还是不行,很奇怪啊. 解决这些乱码时,涉及到了http ...
- Linux内核编译安装
1. .config 复制一份当前系统编译时的配置,在/usr/src目录下 $ ls /usr/src/ linux-headers-4.10.0-35 linux-headers-4.8.0-36 ...
- Django学习笔记-2018.11.16
知识储备: 1 Python基础 2 数据库SQL 3 HTTP协议 4 HTML&&CSS 5 正则表达式 Django启动 django-admin startproject pr ...
- windows下重置mysql的root密码方法介绍(转)
自己在内网操作的,遇到了一些的问题,其中一个是需要重置密码的,所以网上找了两篇文章,都有一些借鉴的地方. 版本mysql5.7.2,linux系统 除了参考文章还有几点说明: service mysq ...