题目链接: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. Go 的文件系统抽象 Afero

    Afero 是一个文件系统框架,提供一个简单.统一和通用的 API 和任何文件系统进行交互,作为抽象层还提供了界面.类型和方法.Afero 的界面十分简洁,设计简单,舍弃了不必要的构造函数和初始化方法 ...

  2. windows下捕获dump之Google breakpad_client

    breakpad是Google开源的一套跨平台工具,用于dump的处理.很全的一套东西,我这里只简单涉及breakpad客户端,不涉及纯文本符号生成,不涉及dump解析. 一.使用 最简单的是使用进程 ...

  3. Win8 Metro(C#)数字图像处理--2.55OSTU法图像二值化

    原文:Win8 Metro(C#)数字图像处理--2.55OSTU法图像二值化  [函数名称] Ostu法图像二值化      WriteableBitmap OstuThSegment(Writ ...

  4. .NET重思(二)接口和抽象类的取舍

    不得不说,接口和抽象类好像啊~两者都不可以实例化,并且未实现的部分都是由派生类实现的. 他们主要有这么个区别: (1)抽象类的派生类可以是派生类,换言之,抽象成员在派生类中不一定完全实现,而接口要求其 ...

  5. AspNetCore 小记

    1. Microsoft.AspNetCore.Hosting.IHostingEnvironment 的接口获取的值: WebRootPath:D:\参考资料\C#\AspNetCore开源项目\n ...

  6. 解决xp越来越慢的办法(其中有些自动备份的功能)

    1.减少磁盘空间占用2.终止不常用的系统服务3.安全问题4.另外一些技巧 首先问一下,你是不是很想激活XP,不...准确的说你是不是想在ms的站上能够升级.如果答案是肯定的话,那我们就先来探讨一下安装 ...

  7. 将QT开发的界面程序封装成DLL,在VC中成功调用(必须有消息循环,所以使用了QTWinmigrate,附CSDN可下载的Demo)

    最近手头的一个项目需要做一个QT界面,并且封装成DLL,然后再动态调用DLL给出的接口函数,使封装在DLL内部的QT界面跑起来,在网上查了很多资料,今天终于成功了,经验不敢独享,因为CSDN给了我很多 ...

  8. Qt常见皮肤qss代码(有Metro的风格)

    ##QTabWidget 淡蓝色效果TabWidget(属性值lightblue) QTabWidget[lightblue = "true"] QTabBar::tab{ bor ...

  9. 海康威视频监控设备Web查看系统(一):概要篇

    声明:本系列文章只提供交流与学习使用.文章中所有涉及到海康威视设备的SDK均可在海康威视官方网站下载得到.文章中所有除官方SDK意外的代码均可随意使用,任何涉及到海康威视公司利益的非正常使用由使用者自 ...

  10. Codility---BinaryGap

    Task description A binary gap within a positive integer N is any maximal sequence of consecutive zer ...