A - 王之迷宫

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
Submit Status

王被困在了一个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 and output

Sample Input Sample Output
3 4 5
S....
.###.
.##..
###.# #####
#####
##.##
##... #####
#####
#.###
####E 1 3 3
S##
#E#
### 0 0 0
Escaped in 11 minute(s).
Trapped!

解题报告:

简单bfs,直接跑就完了

#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;
char g[][][];
bool vis[][][];
int l,r,c;
int dir[][] = {-,,,,,,,-,,,,,,,-,,,};
typedef struct status
{
int x,y,z,step;
status(const int &x,const int &y,const int &z,const int &step)
{
this->x = x , this->y = y, this->z = z ,this->step = step;
}
}; queue<status>q;
int tarx,tary,tarz; bool judge(int x,int y,int z)
{
if (g[z][x][y] == '#' || x >= r || x < || y >= c || y < || z >= l || z < )
return false;
return true;
} int bfs()
{
while(!q.empty())
{
status ns = q.front();q.pop();
if (ns.x == tarx && ns.y == tary && ns.z == tarz)
return ns.step;
int x = ns.x , y = ns.y , z = ns.z , step = ns.step;
for(int i = ; i < ; ++ i)
{
int newx = x + dir[i][];
int newy = y + dir[i][];
int newz = z + dir[i][];
if(!judge(newx,newy,newz) || vis[newx][newy][newz])
continue;
vis[newx][newy][newz] = true;
q.push(status(newx,newy,newz,step+));
}
}
return -;
} int main(int argc,char *argv[])
{
while(scanf("%d%d%d",&l,&r,&c) && l )
{
for(int i = ; i < l ; ++ i)
for(int j = ; j < r ; ++ j)
scanf("%s",g[i][j]);
int stx,sty,stz;
for(int i = ; i < l ; ++ i)
for(int j = ; j < r ; ++ j)
for(int k = ; k < c ; ++ k)
{
if (g[i][j][k] == 'S')
stx = j,sty = k,stz = i;
if (g[i][j][k] == 'E')
tarx = j,tary = k , tarz = i;
}
while(!q.empty())
q.pop();
memset(vis,false,sizeof(vis));
vis[stx][sty][stz] = true;
q.push(status(stx,sty,stz,));
int ans = bfs();
if (ans != -)
printf("Escaped in %d minute(s).\n",ans);
else
printf("Trapped!\n");
}
return ;
}

UESTC_王之迷宫 2015 UESTC Training for Search Algorithm & String<Problem A>的更多相关文章

  1. UESTC_吴队长征婚 2015 UESTC Training for Search Algorithm & String<Problem E>

    E - 吴队长征婚 Time Limit: 10000/4000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submi ...

  2. UESTC_韩爷的梦 2015 UESTC Training for Search Algorithm & String<Problem N>

    N - 韩爷的梦 Time Limit: 200/100MS (Java/Others)     Memory Limit: 1300/1300KB (Java/Others) Submit Stat ...

  3. UESTC_秋实大哥の恋爱物语 2015 UESTC Training for Search Algorithm & String<Problem K>

    K - 秋实大哥の恋爱物语 Time Limit: 5000/2000MS (Java/Others)     Memory Limit: 32000/32000KB (Java/Others) Su ...

  4. UESTC_全都是秋实大哥 2015 UESTC Training for Search Algorithm & String<Problem J>

    J - 全都是秋实大哥 Time Limit: 5000/2000MS (Java/Others)     Memory Limit: 32000/32000KB (Java/Others) Subm ...

  5. UESTC_基爷的中位数 2015 UESTC Training for Search Algorithm & String<Problem D>

    D - 基爷的中位数 Time Limit: 5000/3000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submi ...

  6. UESTC_基爷与加法等式 2015 UESTC Training for Search Algorithm & String<Problem C>

    C - 基爷与加法等式 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Subm ...

  7. UESTC_邱老师降临小行星 2015 UESTC Training for Search Algorithm & String<Problem B>

    B - 邱老师降临小行星 Time Limit: 10000/5000MS (Java/Others)     Memory Limit: 65536/65535KB (Java/Others) Su ...

  8. UESTC_Palindromic String 2015 UESTC Training for Search Algorithm & String<Problem M>

    M - Palindromic String Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 128000/128000KB (Java ...

  9. UESTC_Ferris Wheel String 2015 UESTC Training for Search Algorithm & String<Problem L>

    L - Ferris Wheel String Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 43000/43000KB (Java/ ...

随机推荐

  1. GitHub使用说明

    登陆https://github.com/,并注册账号 从如下地址下载windows客户端:https://msysgit.googlecode.com/files/Git-1.8.4-preview ...

  2. UGUI Button和Toogle动态添加事件

    如果你想动态创建Button和Toogle 等等一系列控件,需要动态添加事件的如下. 拿button和Toogle抛砖引玉O(∩_∩)O~ using UnityEngine; using Syste ...

  3. java与.net比较学习系列(1) 开发环境和常用调试技巧

    最近因为公司项目要由.net平台转到java平台的原因,之前一直用.net的我不得不开始学习java了,刚开始听到说要转java的时候很抗拒,因为我想专注在.net平台上,不过这样也并不完全是坏事,通 ...

  4. class、interface、struct的差别

    1 struct和class有什么差别 1.1默认的继承訪问权限 Struct是public的,class是private的. 你能够写例如以下的代码: struct A { char a; }; s ...

  5. C++入门学习——标准模板库之vector

    vector(向量容器),是 C++ 中十分实用一个容器.vector 之所以被觉得是一个容器,是由于它可以像容器一样存放各种类型的对象,简单地说,vector 是一个可以存放随意类型(类型可以是in ...

  6. linux 系统下配置安装 java jdk 图文流程

    先查看一下系统版本,本例采用的操作系统是CentOS 6.5: 如果你是初装之后的操作系统,那么有可能wget这个组件是不存在的,所以你要安装一下它,这样才可以让你从网上down下你要的安装包: 上面 ...

  7. docker 数据管理

    一,介于创建docker容器退出或者删除容器数据无法得以保存以及docker容器中的分区较小的问题存在,未解决该问题,可以使用参考以下几种方法. 1,将宿主的目录挂载到容器中去. docker run ...

  8. 细讲encodeURI和encodeURIComponent以及escape的区别与应用

    首先,我们都知道这三个东西都是用来编码的 先来说encodeURI()和encodeURIComponent() 这两个是在转换url时候用来编码解码用的. 有编码就会有解码, 解码就是decodeU ...

  9. javascript,css3加载动画

    html代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <me ...

  10. web.cofing(新手必看)

    花了点时间整理了一下ASP.NET Web.config配置文件的基本使用方法.很适合新手参看,由于Web.config在使用很灵活,可以自定义一些节点.所以这里只介绍一些比较常用的节点. <? ...