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(0<l,r,c≤30)。

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

3 4 5
S....
.###.
.##..
###.#

#####
#####
##.##
##...

#####
#####
#.###
####E

1 3 3
S##
#E#
###

0 0 0

Sample Output

Escaped in 11 minute(s).
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的更多相关文章

  1. 2015 UESTC 搜索专题F题 Eight Puzzle 爆搜

    Eight Puzzle Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 ...

  2. 2015 UESTC 搜索专题K题 秋实大哥の恋爱物语 kmp

    秋实大哥の恋爱物语 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 De ...

  3. 2015 UESTC 搜索专题E题 吴队长征婚 爆搜

    吴队长征婚 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Descri ...

  4. 2015 UESTC 搜索专题B题 邱老师降临小行星 记忆化搜索

    邱老师降临小行星 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Des ...

  5. 2015 UESTC 搜索专题N题 韩爷的梦 hash

    韩爷的梦 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Descrip ...

  6. 2015 UESTC 搜索专题M题 Palindromic String 马拉车算法

    Palindromic String Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/s ...

  7. 2015 UESTC 搜索专题J题 全都是秋实大哥 kmp

    全都是秋实大哥 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Desc ...

  8. 2015 UESTC 搜索专题D题 基爷的中位数 二分

    基爷的中位数 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Descr ...

  9. 2015 UESTC 搜索专题C题 基爷与加法等式 爆搜DFS

    基爷与加法等式 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Desc ...

随机推荐

  1. python requests模块手动设置cookies的几种方式

    def use_cookie(self): cookies="YF-V5-G0=731b77772529a1f49eac82a9d2c2957f; SUB=_2AkMsEgief8NxqwJ ...

  2. .htaccess技巧: URL重写(Rewrite)与重定向(Redirect)

    URL重定向是.htaccess的重头戏,它可以将长地址转为短地址.将动态地址转为静态地址.重定向丢失的页面.防止盗链.实现自动语言转换等.笔者觉得难点是在正则表达式的运用和理解上. 实现所有这些神奇 ...

  3. Linux下快速查找文件

    1 locate 查找内容.查找数据库,updatedb命令更新数据库 2 which 命令 3 find 路径 -name 查找内容.find命令会磁盘查找,比较耗时. 4 grep 查找内容一般为 ...

  4. deep learning 资源汇总

    不定时更新..... 首先是吴老爷子在优酷的视频,可惜外音太大了:http://list.youku.com/albumlist/show?id=21508721&ascending=1&am ...

  5. POJ 2337 Catenyms(欧拉回(通)路:路径输出+最小字典序)

    题目链接:http://poj.org/problem?id=2337 题目大意:给你n个字符串,只有字符串首和尾相同才能连接起来.请你以最小字典序输出连接好的单词. 解题思路:跟POJ1386一个意 ...

  6. poj 1041(字典序输出欧拉回路)

    John's trip Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8641   Accepted: 2893   Spe ...

  7. Construct Binary Tree from Inorder and Postorder Traversal (&&Preorder and Inorder Traversal )——数据结构和算法的基本问题

    Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume tha ...

  8. 04 java 基础:数据类型

    java 数据类型:基本类型与引用类型 基本类型:数值型,其中数值型分为整型.浮点型,整型包括 byte.short .int.long ,默认为 int 类型.浮点类型分为单精度.双精度,分为 fl ...

  9. char *s 和char s[]的区别

    char *s 和 char s[] 的区别小结 博客分类: C语言 c教育 . 最近的项目中有不少c的程序,在与项目新成员的交流中发现,普遍对于char *s1 和 char s2[] 认识有误区( ...

  10. loadrunner场景中按scenario和group执行的区别

    group:多个脚本之间按照独立设置模式跑,各个脚本可以单独设置虚拟用户.运行时间等 scenario:多个脚本之间按照相同的模式跑,将总的虚拟用户数按照一定的比例分配给各个脚本