Dungeon Master POJ - 2251 [kuangbin带你飞]专题一 简单搜索
Is an escape possible? If yes, how long will it take?
Input
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! 三维bfs水题,但鉴于自己好久没有做bfs,忘记了vis数组放哪里和取值,最最重要的是中间一行代码写错了,害我debug半天
bfs模板题
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
int dx[]={,,-,,,},dy[]={,-,,,,},dz[]={,,,,,-};
int t,n,m,sx,sy,sz,ex,ey,ez,vis[][][];
char mapn[][][];
struct node{
int x,y,z,step;
};
void bfs(){
node p;
p.x = sx,p.y = sy,p.z = sz;
vis[sx][sy][sz] = ;
p.step = ;
queue<node> q;
q.push(p);
while(!q.empty()){
node tmp = q.front();
q.pop();
if(tmp.x == ex && tmp.y == ey && tmp.z == ez){
cout << "Escaped in " << tmp.step << " minute(s)." << endl;
return;
}
for(int i=;i<;i++){
int xx = tmp.x + dx[i];
int yy = tmp.y + dy[i];
int zz = tmp.z + dz[i];
if(mapn[xx][yy][zz] != '#' && xx> && xx<=t && yy> && yy<=n && zz> && zz<=m && !vis[xx][yy][zz]){
node tp;
tp.x = xx;
tp.y = yy;
tp.z = zz;
tp.step = tmp.step + ;//这一行代码,开始写成了tp.step++;
vis[xx][yy][zz] = ;
q.push(tp);
}
}
}
cout << "Trapped!" << endl;
}
int main(){
while(cin >> t >> n >> m){
if(t == || n == || m == ){
break;
}
memset(vis,,sizeof(vis));
for(int i=;i<=t;i++){
for(int j=;j<=n;j++){
for(int k=;k<=m;k++){
cin >> mapn[i][j][k];
if(mapn[i][j][k] == 'S'){
sx = i,sy = j,sz = k;
}
if(mapn[i][j][k] == 'E'){
ex = i,ey = j,ez = k;
}
}
}
}
bfs();
}
return ;
}
Dungeon Master POJ - 2251 [kuangbin带你飞]专题一 简单搜索的更多相关文章
- 迷宫问题 POJ - 3984 [kuangbin带你飞]专题一 简单搜索
定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, ...
- Catch That Cow POJ - 3278 [kuangbin带你飞]专题一 简单搜索
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. ...
- 棋盘问题 POJ - 1321 [kuangbin带你飞]专题一 简单搜索
在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C. ...
- [kuangbin带你飞]专题一 简单搜索(回顾)
A - 棋盘问题 POJ - 1321 注意条件:不能每放一个棋子,就标记一行和一列,我们直接枚举每一行就可以了. AC代码: #include<iostream> #include< ...
- [kuangbin带你飞]专题一 简单搜索
ID Origin Title 454 / 1008 Problem A POJ 1321 棋盘问题 328 / 854 Problem B POJ 2251 Dungeon Ma ...
- [kuangbin带你飞]专题一 简单搜索 - B - Dungeon Master
#include<iostream> #include<cstdio> #include<string> #include<vector> #inclu ...
- [kuangbin带你飞]专题一 简单搜索 题解报告
又重头开始刷kuangbin,有些题用了和以前不一样的思路解决.全部题解如下 点击每道题的标题即可跳转至VJ题目页面. A-棋盘问题 棋子不能摆在相同行和相同列,所以我们可以依此枚举每一行,然后标记每 ...
- [kuangbin带你飞]专题一 简单搜索 x
A - 棋盘问题 POJ - 1321 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋 ...
- [kuangbin带你飞]专题一 简单搜索 - E - Find The Multiple
//Memory Time //2236K 32MS #include<iostream> using namespace std; ]; //保存每次mod n的余数 //由于198的余 ...
随机推荐
- Tomcat发布War包或者Maven项目
在tomcat的conf目录下面的server.xml中修改如下: Host name="localhost" appBase="webapps" unpac ...
- Redis优化建议
优化的一些建议 1.尽量使用短的key 当然在精简的同时,不要完了key的"见名知意".对于value有些也可精简,比如性别使用0.1. 2.避免使用keys * keys *, ...
- istio入门教程
广告 | kubernetes各版本离线安装包 安装 安装k8s 强势插播广告 三步安装,不多说 安装helm, 推荐生产环境用helm安装,可以调参 release地址 如我使用的2.9.1版本 y ...
- 【Kubernetes 系列四】Kubernetes 实战:管理 Hello World 集群
目录 1. 创建集群 1.1. 安装 kubectl 1.1.1. 安装 kubectl 到 Linux 1.1.2. 安装 kubectl 到 macOS 1.1.3. 安装 kubectl 到 W ...
- Java Web基础面试题整理
Tomcat的缺省端口是多少,怎么修改 tomcat默认缺省端口是8080 修改方法: 找到Tomcat目录下的conf文件夹 进入conf文件夹里面找到server.xml文件 打开server.x ...
- Linux--shell重定向与文件处理命令--02
一.IO重定向 1.数据输入:键盘---标准输入,但并不是唯一输入方式 ” | passwd –stdin username #同时添加用户和密码 while line;do 循环体...$line ...
- 从SpringBoot构建十万博文聊聊高并发文章浏览量设计
前言 在经历了,缓存.限流.布隆穿透等等一系列加强功能,十万博客基本算是成型,网站上线以后也加入了百度统计来见证十万+ 的整个过程. 但是百度统计并不能对每篇博文进行详细的浏览量统计,如果做一些热点博 ...
- 如何利用jenkins插件查看allure报告-----完整篇(解决404和无数据问题)
背景: python3+appium+pytest+allure写了安卓的自动化脚本,在windows本机pycharm上跑通过后生成了allure报告. 公司jenkins搭建在linux服务器上 ...
- Vue+springboot管理系统
About 此项目是vue+element-ui 快速开发的物资管理系统,后台用的java springBoot 所有数据都是从服务器实时获取的数据,具有登陆,注册,对数据进行管理,打印数据等功能 说 ...
- spring-boot-plus V1.2.2 发布,5 Minutes Finish CRUD
更新日志 CHANGELOG [V1.2.2-RELEASE] 2019.08.26