题目链接: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. wpf窗体定位

    原文:wpf窗体定位 据WPF外包小编了解,通常,不需要在屏幕上明确定位窗口.而是简单地将WindowState属性设置为Normal,并忽略其他所有细节.另一方面,很少会将WindowStartup ...

  2. js错误界面

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  3. WPF Layout 系统概述——Measure

    原文:WPF Layout 系统概述--Measure 前言 在WPF/Silverlight当中,如果已经存在的Element无法满足你特殊的需求,你可能想自定义Element,那么就有可能会面临重 ...

  4. WPF,通过修改dataGrid的cell的style,改变选中行失去焦点时的颜色 4.0可用

    <Style TargetType="{x:Type DataGridCell}"> <Style.Triggers> <Trigger Proper ...

  5. ubuntu Linux 操作系统安装与配置

    Ubuntu是一个以桌面应用为主的Linux操作系统.Ubuntu每六个月发布一个新版本(一般是4和10月份,命名为YY.MM),每一个普通版本都将被支持 18个月,长期支持版(Long Term S ...

  6. IT回忆录-2

    随着网络的发展,下载工具也不断地更新. 印象比较深的下载工具,从网络蚂蚁.网际快车,到BT. BT出来的时候,对下载真的是一个革命啊,以前下载东西,下载的人越多肯定就越慢,我们之前还会跑到一些FTP上 ...

  7. Android零基础入门第50节:StackView卡片堆叠

    原文:Android零基础入门第50节:StackView卡片堆叠 上一期学习了AdapterViewFilpper的使用,你已经掌握了吗?本期开始学习StackView的使用. 一.认识StackV ...

  8. Linux下如何查看高CPU占用率线程 专题

    Java 系统性能分析 命令 1. cpu分析 top , pidstat(sysstat) pid -p PID -t 1 10 vmstat 1 CPU上下文切换.运行队列.利用率 ps Hh - ...

  9. c#基于Tablet pc实现的手写输入

    需要安装Tablet pc,win7的话 直接在控制面板>程序和应用>添加组建里面勾选上添加 然后就是下面的程序了,看代码 设计文件 namespace 手写识别 { partial cl ...

  10. excel导入到数据库的异常处理

    excel导入到数据库,这个是经常发生的,今天就碰到了一个非常郁闷的事情,在导入到oracle数据的时候,总是出现ORA-01756: 引号内的字符串没有正确结束,认真的排插了数据当中可能出现的错误, ...