UESTC_王之迷宫 2015 UESTC Training for Search Algorithm & String<Problem A>
A - 王之迷宫
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
王被困在了一个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 |
Escaped in 11 minute(s). |
解题报告:
简单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>的更多相关文章
- UESTC_吴队长征婚 2015 UESTC Training for Search Algorithm & String<Problem E>
E - 吴队长征婚 Time Limit: 10000/4000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
- 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 ...
- UESTC_秋实大哥の恋爱物语 2015 UESTC Training for Search Algorithm & String<Problem K>
K - 秋实大哥の恋爱物语 Time Limit: 5000/2000MS (Java/Others) Memory Limit: 32000/32000KB (Java/Others) Su ...
- UESTC_全都是秋实大哥 2015 UESTC Training for Search Algorithm & String<Problem J>
J - 全都是秋实大哥 Time Limit: 5000/2000MS (Java/Others) Memory Limit: 32000/32000KB (Java/Others) Subm ...
- UESTC_基爷的中位数 2015 UESTC Training for Search Algorithm & String<Problem D>
D - 基爷的中位数 Time Limit: 5000/3000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
- UESTC_基爷与加法等式 2015 UESTC Training for Search Algorithm & String<Problem C>
C - 基爷与加法等式 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Subm ...
- UESTC_邱老师降临小行星 2015 UESTC Training for Search Algorithm & String<Problem B>
B - 邱老师降临小行星 Time Limit: 10000/5000MS (Java/Others) Memory Limit: 65536/65535KB (Java/Others) Su ...
- 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 ...
- 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/ ...
随机推荐
- Inorder Successor in BST 解答
Question Given a binary search tree and a node in it, find the in-order successor of that node in th ...
- html天气预报小插件
<head></head> <body> <iframe width="225" scrolling="no" hei ...
- 【转】Android中自动连接到指定SSID的Wi-Fi
最近在做一个项目,其中涉及到一块“自动连接已存在的wifi热点”的功能,在网上查阅了大量资料,五花八门,但其中一些说的很简单,即不能实现傻瓜式的拿来就用,有些说的很详细,但其中不乏些许错误造成功能无法 ...
- linux下部署svn服务器
系统Linux debian 2.6.32-5-686 先安装svn工具:apt-get install subversion,耐心等待安装完成.安装完成后svn客户端.服务器都有了. 接者建立svn ...
- C#开发客户端、JAVA和tomcat开发服务端
hessian入门,Hello和文件上传范例,C#客户端+Java Tomcat后台 2.Hello范例1)后台--定义Java接口:package org.migle.hessian; public ...
- XShell连接CentOS 7.2显示中文乱码问题的解决方法
背景 使用U盘往Windows主机.Linux主机传文件还是经常的事,但有时候文件名有中文, 传到Linux机器会有乱码,选择起来也很麻烦,最近刚好遇到,写下解决方法. 环境 Linux [root@ ...
- TCP/IP远程访问操作:rwho,rlogin,rcp和rsh
TCP/IP网络通信 软件 包使用远程访问 的 命令 ,这些命令首先是由UC Berkely为Arpanet开发的.它允许您远程注册到另一个 系统 中,并从一个系统复制文件到另一个系统.您能取得关于一 ...
- iOS8 Core Image In Swift:更复杂的滤镜
iOS8 Core Image In Swift:自动改善图像以及内置滤镜的使用 iOS8 Core Image In Swift:更复杂的滤镜 iOS8 Core Image In Swift:人脸 ...
- jQuery对象和dom对象之间的相互转化
var domObj = document.getElementById("demo"); var $Obj = $("#demo"); DOM转jQuery: ...
- 带CheckBox的TreeView网上出错问题解决办法
问题描述:TreeView上传到服务器,预览效果发现节点图片不显示.展开合并功能缺失.解决办法: 以下是我个人的解决办法,最终的效果实现了,但是还有一点点小遗憾,就是页面上有基于微软的调用js的报错信 ...