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表示白色格子,奶牛每次可以踩一个格子,踩到的格子和它周围的上下左右格子都会翻面,也 ...
随机推荐
- 【python】-- 元组、字典
元组 元组其实跟列表差不多,也是存一组数,只不是它一旦创建,便不能再修改,所以又叫只读列表 用途:一般情况下用于自己写的程序能存下数据,但是又希望这些数据不会被改变,比如:数据库连接信息等 1.访问元 ...
- JDK动态代理连接池
JDK动态代理 1 什么是JDK动态代理 刚刚写ItcastConnection时爽么?因为Connection中的方法太多了,每个都要写,所以很累吧.累点到是没什么,可以完成功能就是好的.但是不 ...
- Alex 的 Hadoop 菜鸟教程: 第2课 hadoop 安装教程 (CentOS6 CDH分支 yum方式)
原帖地址:http://blog.csdn.net/nsrainbow/article/details/36629339 我们这个教程是在 centos 上安装cdh的教程,并且使用的是yum方式. ...
- Java 迭代器
1.快速报错 public class FailFast { public static void main(String[] args) { List<String> c = new A ...
- docker 存储定义成direct-lvm 模式
配置direct-lvm模式 1. 停止Docker systemctl stop docker 2. 安装依赖包 device-mapper-persistent-data,lvm2, and ...
- mysql 5.5 安装配置方法图文教程(转发)
MySQL下载地址:http://dev.mysql.com/downloads/installer/ 1.首先进入的是安装引导界面 2.然后进入的是类型选择界面,这里有3个类型:Typical(典型 ...
- [转]Mysql命令
1.连接Mysql 格式: mysql -h主机地址 -u用户名 -p用户密码 1.连接到本机上的MYSQL.首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u root ...
- 20165101刘天野 2017-2018-2 《Java程序设计》第2周学习总结
# 20165101刘天野 2017-2018-2 <Java程序设计>第2周学习总结 教材学习内容总结 基本数据类型 逻辑类型:boolean 整型:byte.short.int.lon ...
- codeforces 686B
题意:给出一个序列,只允许进行相邻的两两交换,给出使序列变为非降序列的操作方案. 思路:关键点是操作次数不限,冒泡排序. #include<iostream> #include<cs ...
- 编码,charset,乱码,unicode,utf-8与net简单释义
1.文件分为文本文件和二进制文件﹐不过本质都一样﹐都是些01. 2.计算机存储设备存储的0或1﹐称为计算机的一个二进制位(bit). 3.二进制文件的0和1有专门的应用程序来读﹐所以它们没有什么乱不乱 ...