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. Linux 使用yum工具

    Red Hat 发行版安装后无法使用yum,须注册方可使用,可以通过以下方式处理:cd /etc/yum.repos.d/备份目录下已经存在的repo文件,然后新建文件local.repo,具体脚本如 ...

  2. 构建高性能web站点笔记一

    构建高性能web站点笔记 第三章 服务器并发处理能力 3.1吞吐率 描述服务器在实际运行期间单位时间内处理的请求数.也就是一定并发用户的情况下,服务器处理请求能力的量化体现. 吞吐率的前提包括: 并发 ...

  3. ubuntu 右键新建文档

    第一步.创建一个空白doc文档. 一定要是空白的,然后保存(另存为)到桌面,注意细节:1.保存到你能找到的地方,最好是桌面,以方便第二步拖动 2.注意下方的 “文件类型”,要选择doc格式. 3.注意 ...

  4. POJ3260:The Fewest Coins(混合背包)

    Description Farmer John has gone to town to buy some farm supplies. Being a very efficient man, he a ...

  5. Linux正則表達式-反复出现的字符

    星号(*)元字符表示它前面的正則表達式能够出现零次或多次.也就是说,假设它改动了单个字符.那么该字符能够在那里也能够不在那里,而且假设它在那里,那可能会不止出现一个.能够使用星号元字符匹配出如今引號中 ...

  6. [Hapi.js] Logging with good and good-console

    hapi doesn't ship with logging support baked in. Luckily, hapi's rich plugin ecosystem includes ever ...

  7. UIImage与UIColor互转

    Objective-C UIColor -> UIImage ? 1 2 3 4 5 6 7 8 9 10 11 - (UIImage*) createImageWithColor: (UICo ...

  8. Timer.4 - Using a member function as a handler

    In this tutorial we will see how to use a class member function as a callback handler. The program s ...

  9. 本博客弃用,请移步http://ningios.com查看最新

    本博客弃用,请移步http://ningios.com查看最新

  10. Linux远程登录

    Linux远程登录 远程登录 关闭linux的防火墙 /etc/init.d/iptables stop 启动VNC服务器 Vncserver & 然后记住desktop is localho ...