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. 如何使用WCF调试器WcfTestClient.exe

    如果启用服务出现如下异常 请启用下面该服务 C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE 文件->添加服务  地 ...

  2. Java 安装配置

    1.下载 进入官方网站,点击下载链接进入下载页面,选择合适的版本(如,jdk-6u31-windows-i586.exe)下载. 2.安装 双击jdk-6u31-windows-i586.exe文件, ...

  3. hdu 5642 King's Order(数位dp)

    Problem Description After the king's speech , everyone is encouraged. But the war is not over. The k ...

  4. [bzoj1003][ZJOI2006][物流运输] (最短路+dp)

    Description 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线,以便对整个运输过程实施严格 ...

  5. AC Milan VS Juventus(模拟)

    AC Milan VS Juventus Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Oth ...

  6. (HYSBZ)BZOJ 1588 营业额统计

    营业额统计 Time Limit: 5000MS   Memory Limit: 165888KB   64bit IO Format: %lld & %llu Description 营业额 ...

  7. Servlet实现Session

    (1)首先看一下项目的结构 是在tomcat--webaps下的myWebSites项目 在myWebSites下有仅仅有WEB-INF目录 在WEB-INF目录中有  一下目录(在classes目录 ...

  8. oracle 经典语句集合

    1.一列转多行 方法一: select a.id,  substr(','||a.name||',',instr(','||a.name,',',1,b.rn)+1,    instr(a.name| ...

  9. @synthesize

    @synthesize 相当于把属性当成成员变量来用,不用再写self.属性@synthesize myButton; 这样写了之后,那么编译器会自动生成myButton的实例变量,以及相应的gett ...

  10. GridView+ZedGraph【转】

    edgraph图表控件的强大功能令人出乎意料,与OWC相比我想应该毫不逊色,近来需求要求作出相关数据统计,不想使用BI这类的强大东西,所以搜索到 了免费的开源的Zedgraph控件.使用起来也非常方便 ...