kuangbin专题 专题一 简单搜索 Dungeon Master POJ - 2251
题目链接: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的更多相关文章
- Dungeon Master POJ - 2251 (搜索)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 48605 Accepted: 18339 ...
- Dungeon Master poj 2251 dfs
Language: Default Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16855 ...
- 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 ...
- (广搜)Dungeon Master -- poj -- 2251
链接: http://poj.org/problem?id=2251 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2137 ...
- B - Dungeon Master POJ - 2251
//纯bfs #include <iostream> #include <algorithm> #include <cstring> #include <cs ...
- Dungeon Master POJ - 2251(bfs)
对于3维的,可以用结构体来储存,详细见下列代码. 样例可以过,不过能不能ac还不知道,疑似poj炸了, #include<iostream> #include<cstdio> ...
- kuangbin专题总结一 简单搜索
A - 棋盘问题:在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有 ...
- kuangbin专题 专题一 简单搜索 迷宫问题 POJ - 3984
题目链接:https://vjudge.net/problem/POJ-3984 这个题目,emm,上代码,看的估计应该是刚开始接触搜索的,我带点注释,你能慢慢理解. #include <ios ...
- kuangbin专题 专题一 简单搜索 Prime Path POJ - 3126
题目链接:https://vjudge.net/problem/POJ-3126 题意:给你两个四位的素数N,M,每次改变N四位数中的其中一位,如果能经过有限次数的替换变成四位数M,那么求出最少替换次 ...
随机推荐
- PHP获得指定日期所在星期的第一天和最后一天
function getdays($day){ $lastday=date('Y-m-d',strtotime("$day Sunday")); $firstday=date('Y ...
- Microsoft Enterprise Library 5.0 系列(四)
企业库日志应用程序模块工作原理图: 从上图我们可以看清楚企业库日志应用程序模块的工作原理,其中LogFilter,Trace Source,Trace Listener,Log Formatter的信 ...
- Win10《芒果TV》送7天免费会员,邀您抢先看萌心自制《妈妈是超人3》
<妈妈是超人>第三季萌心归来,霍思燕,贾静雯,黄圣依,邓莎联合释放"妈妈的声音",嗯哼,咘咘,波妞,安迪,大麟子五位萌娃共同出镜,萌化屏幕.Win10<芒果TV& ...
- C# 屏蔽Ctrl Alt Del 快捷键方法+屏蔽所有输入
原文:C# 屏蔽Ctrl Alt Del 快捷键方法+屏蔽所有输入 Win32.cs /* * * FileCreate By Bluefire * Used To Import WindowsApi ...
- WPF应用App.Config文件的保存路径
App.Config文件有更改后,自动会保存到以下路径: C:\Users\你的系统用户名\AppData\Local\你的应用名\
- FireUI live Preview使用方法-Berlin
这是可以让开发者事先预览 mobile 画面的作法 1.先确定 Berlin IDE Tools\Option\Form Designer 中 FireUI live Preview broad ...
- Delphi中TResourceStream流使用
Resource可以是任意文件(图像.声音.office都可以),直接打包到编译的exe文件中,调用也非常方便 打开一个新的或已有的delphi工程 1.先在 Project->resource ...
- 运维不仅仅是Linux,居然还要知道这么多?
摘要: 运维不仅仅是懂Linux就行,因为还有一大部分的Windows运维,向windows运维人员致敬.当然我们这篇文章不是说运维除了懂Linux,还要懂Windows,而是涉及运维的其他方方面面. ...
- U盘免疫
界面如下: 关键部分代码如下: void CImmunityUDlg::OnBnClickedButtonOk() { // TODO: 在此添加控件通知处理程序代码 TCHAR szPath[MAX ...
- Linux历史,安装,分区,版本
Linux 历史 1970年是 UNIX元年,这一年 Kenneth Lane Thompson 和 Dennis Ritchie 合作编写了UNIX系统. Stallman 发起了GNU 计划,他本 ...