题目链接:https://vjudge.net/problem/POJ-2251

题意:简单的三维地图

思路:直接上代码。。。


 #include <iostream>
#include <string.h>
#include<queue>
#include <algorithm>
using namespace std; #define rep(i,j,k) for(int i = (j); i <= (k); i++)
#define per(i,j,k) for(int i = (j); i >= (k); i--) const int N = ;
int mv_x[] = { , , , , , - };
int mv_y[] = { , , , -, , };
int mv_z[] = { , -, , , , };
char mp[N][N][N];
bool vis[N][N][N];
int sx, sy, sz;//入口
int ex, ey, ez;//出口
int xx,yy,zz,ans; struct node{
int x, y, z, c;
}; void init(){
rep(i, , zz) rep(j, , xx) rep(z, , yy){
vis[i][j][z] = false;
}
} void input(){ rep(i, , zz) rep(j, , xx) rep(z, , yy){
cin >> mp[i][j][z];
if (mp[i][j][z] == 'S'){
sx = j; sy = z; sz = i;
}
else if (mp[i][j][z] == 'E'){
ex = j; ey = z; ez = i;
}
}
} inline bool check(int x, int y, int z){
return x >= && x <= xx
&& y >= && y <= yy
&& z >= && z <= zz;
} bool bfs(){//true为能出去 false不能出去 queue<node> que;
que.push(node{ sx, sy, sz, }); vis[sz][sx][sy] = true; while (!que.empty()){ node tmp = que.front();
que.pop(); rep(p, , ){
int dx = tmp.x + mv_x[p];
int dy = tmp.y + mv_y[p];
int dz = tmp.z + mv_z[p]; if (check(dx, dy, dz) && mp[dz][dx][dy] != '#' && !vis[dz][dx][dy]){ if (dx == ex && dy == ey && dz == ez){//到了出口
ans = tmp.c + ;
return true;
} vis[dz][dx][dy] = true;
que.push(node{ dx, dy, dz ,tmp.c + });
}
}
} return false;
} int main(){ ios::sync_with_stdio(false);
cin.tie(); while (cin >> zz >> xx >> yy){
if (zz == ) break; init();
input(); if (bfs()) cout << "Escaped in " << ans << " minute(s)." << endl;
else cout << "Trapped!" << endl;
} return ;
}

kuangbin专题 专题一 简单搜索 Dungeon Master POJ - 2251的更多相关文章

  1. Dungeon Master POJ - 2251 (搜索)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 48605   Accepted: 18339 ...

  2. Dungeon Master poj 2251 dfs

    Language: Default Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16855 ...

  3. Dungeon Master POJ - 2251 [kuangbin带你飞]专题一 简单搜索

    You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...

  4. (广搜)Dungeon Master -- poj -- 2251

    链接: http://poj.org/problem?id=2251 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2137 ...

  5. B - Dungeon Master POJ - 2251

    //纯bfs #include <iostream> #include <algorithm> #include <cstring> #include <cs ...

  6. Dungeon Master POJ - 2251(bfs)

    对于3维的,可以用结构体来储存,详细见下列代码. 样例可以过,不过能不能ac还不知道,疑似poj炸了, #include<iostream> #include<cstdio> ...

  7. kuangbin专题总结一 简单搜索

    A - 棋盘问题:在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有 ...

  8. kuangbin专题 专题一 简单搜索 迷宫问题 POJ - 3984

    题目链接:https://vjudge.net/problem/POJ-3984 这个题目,emm,上代码,看的估计应该是刚开始接触搜索的,我带点注释,你能慢慢理解. #include <ios ...

  9. kuangbin专题 专题一 简单搜索 Prime Path POJ - 3126

    题目链接:https://vjudge.net/problem/POJ-3126 题意:给你两个四位的素数N,M,每次改变N四位数中的其中一位,如果能经过有限次数的替换变成四位数M,那么求出最少替换次 ...

随机推荐

  1. OpenGL红宝书附带源码编译问题集锦

    以下所有源码均在win7,VS2008环境下测试.下不再赘述. 1.所有的.c扩展名请改为.cpp扩展名,以避免不可预测的错误. 想知道会出现什么不可预测的错误..请见我上一篇Blog... 2.如果 ...

  2. AY写给国人的教程- VS2017 Live Unit Testing[2/2]-C#人爱学不学-aaronyang技术分享

    原文:AY写给国人的教程- VS2017 Live Unit Testing[2/2]-C#人爱学不学-aaronyang技术分享 谢谢大家观看-AY的 VS2017推广系列 Live Unit Te ...

  3. JS如何为iframe添加onclick事件

    如果页面上有iframe时,鼠标点击在iframe内时,包含iframe的document是不响应任何事件的, 例如: $("#iframe1").click(function() ...

  4. Android 9.0 Dialog不显示

    Tester报了一个bug,大概如下: 页面:Activity1 dialog1(半透明遮罩样式) Activity2 dialog2 场景:Activity1弹出dialog1,dialog1弹出a ...

  5. .gitignore 配置后无效

    利用.gitignore过滤文件,如编译过程中的中间文件,等等,这些文件不需要被追踪管理. 现象: 在.gitignore添加file1文件,以过滤该文件,但是通过Git status查看仍显示fil ...

  6. 解决com.android.dex.DexException: Multiple dex files define Lcom/google/gson/JsonSerializer;

    我在开发Windows Azure的Mobile Service(隔天补上创建过程)的安卓客户端时,报出了com.android.dex.DexException: Multiple dex file ...

  7. How To Compile Qt with Visual Studio

    How To Compile Qt with Visual Studio FEBRUARY 1, 2011 This post is a step-by-step guide on how to co ...

  8. ASP.NET vNext 微笔记

    关心 ASP.NET vNext 的人可能已经读过相关文章,例如:ASP.NET vNext @ 2014.那么,你可能已经知道,ASP.NET vNext 摆脱了 System.Web.DLL,把 ...

  9. 为QNetworkAccessManager添加超时提醒(自己记录一段时间里的下载字节数,用定时器去定期检测,从而判断是否超时)

    在做更新,在测试异常的时候,在下载过程中,发现如果直接系统禁用了网络,会报错误,可以捕获.但是如果是第三方软件限制程序联网,问题来了. 程序会一直在那里等待,没有异常,也不发送QNetworkAcce ...

  10. JVM(六):探究类加载过程-下

    JVM(六):探究类加载过程-下 上文说了类加载过程的5个阶段,着重介绍了各个阶段做的工作.在本文中,我们对执行加载阶段的主体进行探讨,学习类加载器的模型和逻辑,以及我们该如何自定义一个类加载器. 定 ...