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的余 ...
随机推荐
- 保存MTLAB图片是想去掉白边
在做一些matlab小实验的时候,生成的图片需要临时保存的时候会有多余的白边,如何能解决这种问题? 输入 iptsetpref('ImshowBorder','tight'); 后,再show一次图即 ...
- 拉格朗日对偶性(Lagrange duality)
目录 拉格朗日对偶性(Lagrange duality) 1. 从原始问题到对偶问题 2. 弱对偶与强对偶 3. KKT条件 Reference: 拉格朗日对偶性(Lagrange duality) ...
- python基础之循环与迭代器
循环 python 循环语句有for循环和while循环. while循环while循环语法 while 判断条件: 语句 #while循环示例 i = 0 while i < 10: i += ...
- vscode c 语言 win10
在看 CSAPP 一些课程,一些c 语言的小程序的例子,想跑起来试试,用一个DEV c++ 简单上手,但这是一个上古的IDE, 前端开发中的代码不全,语法高亮,都不太好,就想着为什么不折腾一下 V ...
- viewpager_轮播
public class MainActivity extends Activity { private ViewPager pager; private int[] id={R.layout.lay ...
- 史上最全面的SignalR系列教程-3、SignalR 实现推送功能-集线器类实现方式
1.概述 通过前两篇 史上最全面的SignalR系列教程-1.认识SignalR 史上最全面的SignalR系列教程-2.SignalR 实现推送功能-永久连接类实现方式 文章对SignalR的介绍, ...
- 《机器学习技法》---对偶SVM
1.对偶问题的推导 为什么要求解对偶问题?一是对偶问题往往更容易求解,二是可以自然的引入核函数. 1.1 用拉格朗日函数将原问题转化为“无约束”等价问题 原问题是: 写出它的拉格朗日函数: 然后我们的 ...
- (三十二)c#Winform自定义控件-表格
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- c语言实现基本的数据结构(一) 线性表
#include <stdio.h> #include <tchar.h> #include <stdlib.h> #define LIST_INIT_SIZE 1 ...
- Python 命令行之旅 —— 深入 argparse (一)
作者:HelloGitHub-Prodesire HelloGitHub 的<讲解开源项目>系列,项目地址:https://github.com/HelloGitHub-Team/Arti ...