virtual judge(专题一 简单搜索 B)
Description
Is an escape possible? If yes, how long will it take?
Input
L is the number of levels making up the dungeon.
R and C are the number of rows and columns making up the plan of each level.
Then there will follow L blocks of R lines each containing C characters. Each character describes one cell of the dungeon. A cell full of rock is indicated by a '#' and empty cells are represented by a '.'. Your starting position is indicated by 'S' and the exit by the letter 'E'. There's a single blank line after each level. Input is terminated by three zeroes for L, R and C.
Output
Escaped in x minute(s).
where x is replaced by the shortest time it takes to escape.
If it is not possible to escape, print the line
Trapped!
Sample Input
3 4 5
S....
.###.
.##..
###.# #####
#####
##.##
##... #####
#####
#.###
####E 1 3 3
S##
#E#
### 0 0 0
Sample Output
Escaped in 11 minute(s).
Trapped! 三维迷宫水题
#include"cstdio"
#include"queue"
#include"cstring"
using namespace std;
const int MAXN=;
char dun[MAXN][MAXN][MAXN];
int vis[MAXN][MAXN][MAXN];
struct node{
int L,R,C;
int step;
node(int l,int r,int c,int s):L(l),R(r),C(c),step(s){}
node(){}
};
int l,r,c;
int sl,sr,sc;
int el,er,ec;
int dl[]={,,,,,-};
int dc[]={,,,-,,};
int dr[]={,,,,-,};
int bfs()
{
queue<node> que;
que.push(node(sl,sr,sc,));
vis[sl][sr][sc]=;
while(!que.empty())
{
node now=que.front();que.pop();
if(now.L==el&&now.R==er&&now.C==ec)
{
return now.step;
}
for(int i=;i<;i++)
{
int nl=now.L+dl[i];
int nr=now.R+dr[i];
int nc=now.C+dc[i];
if(<=nl&&nl<l&&<=nr&&nr<r&&<=nc&&nc<c&&!vis[nl][nr][nc]&&dun[nl][nr][nc]!='#')
{
vis[nl][nr][nc]=;
que.push(node(nl,nr,nc,now.step+));
}
}
}
return -;
}
int main()
{
while(scanf("%d%d%d",&l,&r,&c)!=EOF&&l!=)
{
memset(vis,,sizeof(vis));
scanf("%*c");
for(int i=;i<l;i++)
{
for(int j=;j<r;j++)
{
for(int z=;z<c;z++)
{
scanf("%c",&dun[i][j][z]);
if(dun[i][j][z]=='S')
{
sl=i,sr=j,sc=z;
}
if(dun[i][j][z]=='E')
{
el=i,er=j,ec=z;
}
}
scanf("%*c");
}
scanf("%*c");
} int ans=bfs();
if(ans!=-)
{
printf("Escaped in %d minute(s).\n",ans);
}
else
{
printf("Trapped!\n");
}
}
return ;
}
virtual judge(专题一 简单搜索 B)的更多相关文章
- virtual judge(专题一 简单搜索 E)
Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...
- virtual judge(专题一 简单搜索 C)
Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...
- virtual judge(专题一 简单搜索 A)
问题描述: Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘, ...
- [kuangbin带你飞]专题一 简单搜索 题解报告
又重头开始刷kuangbin,有些题用了和以前不一样的思路解决.全部题解如下 点击每道题的标题即可跳转至VJ题目页面. A-棋盘问题 棋子不能摆在相同行和相同列,所以我们可以依此枚举每一行,然后标记每 ...
- [kuangbin带你飞]专题一 简单搜索(回顾)
A - 棋盘问题 POJ - 1321 注意条件:不能每放一个棋子,就标记一行和一列,我们直接枚举每一行就可以了. AC代码: #include<iostream> #include< ...
- kuangbin专题 专题一 简单搜索 Oil Deposits HDU - 1241
题目链接:https://vjudge.net/problem/HDU-1241 题意:问有几个油田,一个油田由相邻的‘@’,组成. 思路:bfs,dfs都可以,只需要遍历地图,遇到‘@’,跑一遍搜索 ...
- kuangbin专题 专题一 简单搜索 迷宫问题 POJ - 3984
题目链接:https://vjudge.net/problem/POJ-3984 这个题目,emm,上代码,看的估计应该是刚开始接触搜索的,我带点注释,你能慢慢理解. #include <ios ...
- kuangbin专题 专题一 简单搜索 Fire! UVA - 11624
题目链接:https://vjudge.net/problem/UVA-11624 题意:一个迷宫,可能有一个或者多个地方着火了,每过1个时间消耗,火会向四周蔓延,问Joe能不能逃出迷宫,只要走出迷宫 ...
- kuangbin专题 专题一 简单搜索 Fliptile POJ - 3279
题目链接:https://vjudge.net/problem/POJ-3279 题意:格子有两面,1表示黑色格子,0表示白色格子,奶牛每次可以踩一个格子,踩到的格子和它周围的上下左右格子都会翻面,也 ...
随机推荐
- js跨浏览器复制: ZeroClipboard
实例结构: demo.html <script type="text/javascript" src='http://code.jquery.com/jquery.js'&g ...
- TCP协议要点和难点全解
转载自http://www.cnblogs.com/leetieniu2014/p/5771324.html TCP协议要点和难点全解 说明: 1).本文以TCP的发展历程解析容易引起混淆,误会的方方 ...
- Android笔记之获取debug.keystore和release.keystore的MD5/SHA1值
获取debug.keystore的key,如下图 获取release.keystore的key 输入命令keytool -list -v -keystore <jksFilename> 例 ...
- springboot错误页面处理
springboot作为微服务的便捷框架,在错误页面处理上也有了一些新的处理,不同于之前的pringmvc500的页面处理是比较简单的,用java config或者xml的形式,定义如下的Bean即可 ...
- [转]How Hash Algorithms Work
来看看SHA-1到底是如何工作的 http://www.metamorphosite.com/one-way-hash-encryption-sha1-data-software
- linux c编程:进程控制(四)进程关系
每一个进程除了有一个进程ID外,还属于一个进程组. 进程组是一个或多个进程的集合,通常情况下,他们是在同一作业中结合起来的,同一进程组的个进程接受来自同一终端的各种信号. 每一个进程组有一个唯一的进 ...
- python+NLTK 自然语言学习处理八:分类文本一
从这一章开始将进入到关键部分:模式识别.这一章主要解决下面几个问题 1 怎样才能识别出语言数据中明显用于分类的特性 2 怎样才能构建用于自动执行语言处理任务的语言模型 3 从这些模型中我们可以学到那些 ...
- python基础14 ---函数模块5(模块和包)
模块与包 一.模块 1.模块是怎么诞生的. 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护.为了编写可维护的代码,我们把很多函数分组,分别放到 不同的文 ...
- php验证复选框的小例子
发布:thatboy 来源:Net [大 中 小] 本文介绍一个简单的php实例,通过代码验证复选框值的有效性,有需要的朋友,可以参考下. 验证复选框的php代码,如下: <?php ...
- JQuery 双击动态编辑
$(this).append(input); $("input#temp").focus(); $("inp ...