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. YUM配置

    一.yum环境的本地源搭建(基于VSFTP): 1)安装vsftp;    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@         [root ...

  2. 【转】基于Qt, TUIO和TSLIB的嵌入式Linux下的多点触摸设计

    这个教程描述了在嵌入式linux下使用Qt如何设置一个支持多点触摸和单点触摸的输入系统.这里假定你已经有了对应的驱动程序,驱动可以从触摸屏的厂商那里获得或者使用一个linux 内核源码中已经存在的驱动 ...

  3. Maven之——坐标和依赖(上)

    Maven之--坐标和依赖(上) 1.    Maven坐标概念 Maven通过构件的坐标来在Maven仓库中定位到详细的构件.Maven的坐标元素包含groupId.artifactId.versi ...

  4. 利用boost获取时间并格式化

    利用boost来获取当前时间又方便快捷,还不用考虑跨平台的问题. 1. 输出YYYYMMDD #include <boost/date_time/gregorian/gregorian.hpp& ...

  5. hdu 2822 Dogs(优先队列)

    题目链接:hdu2822 会优先队列话这题很容易AC.... #include<stdio.h> #include<string.h> #include<queue> ...

  6. FULL JOIN 与 CROSS JOIN

    FULL JOIN 只要其中某个表存在匹配,FULL JOIN 关键字就会返回行.(返回JOIN 两端表的所有数据,无论其与另一张表有没有匹配.显示左连接.右连接和内连接的并集) FULL JOIN ...

  7. C语言获取键盘按键

    在写控制台游戏的时候,发现不管用cin,scanf还是getchar,都不能实时的输入按键,必须要按回车才能读进去,而按回车的话会导致输入异常,所以要使用获取键盘按键的函数. 加入头文件#includ ...

  8. 不用不知道 apply()与call()的强大

    在看关于javascript继承的时候 好多地方都用到了apply()和call() 之前在简单编程的时候根本没有遇到过 查阅资料后才发现这两个方法是如此的好用. 下面从几方面来看一下这两个方法: 1 ...

  9. bootstrap data- jquery .data

    jquery官网对.data函数描述是:在匹配元素上存储任意相关数据 或 返回匹配的元素集合中的第一个元素的给定名称的数据存储的值. 存储键值(key/value): $("body&quo ...

  10. win8系统intellij输入中文问题

    用上新的intellij,不过在输入汉字时出现后面的被删除,网上找了,没有找到解决方案,只有自己解决了,感觉如果是intellij不兼容win8,那么就不能用intellij,那对于习惯了intell ...