poj2251:http://poj.org/problem?id=2251

题意:给你一个三维的立方体,然后给你一个起点,和终点的坐标。然后让你求从起点到终点的最短路程。
题解:该题就是求三维的最短路,可以采用BFS,三维的BFS。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
int counts[][][];//记录到起点的最短距离
struct Node{
int x;
int y;
int z;
int step;
};
int n,m,l;//长,宽,高
char map1[][][];//原来的三维的地图
int startx,starty,startz;//起点坐标
int endx,endy,endz;//终点坐标
int BFS(int x,int y,int z){
int xxx[]={,,,,-,};
int yyy[]={,,-,,,};
int zzz[]={-,,,,,};//六个方向的对应的3个坐标
for(int i=;i<=l;i++)
for(int j=;j<=n;j++)
for(int k=;k<=m;k++)//初始化
counts[i][j][k]=;
counts[x][y][z]=;//注意这里的初始化
queue<Node>Q;
Node tt;
tt.x=x;tt.y=y;tt.z=z;tt.step=;
Q.push(tt);
while(!Q.empty()){
Node temp=Q.front();
Q.pop();
int xx=temp.x;
int yy=temp.y;
int zz=temp.z;
int step=temp.step;
for(int i=;i<;i++){//六个方向进行搜索
if(xx+xxx[i]>=&&xx+xxx[i]<=n&&yy+yyy[i]>=&&yy+yyy[i]<=m&&zz+zzz[i]>=&&zz+zzz[i]<=l){
if(map1[zz+zzz[i]][xx+xxx[i]][yy+yyy[i]]!='#'&&step+<counts[zz+zzz[i]][xx+xxx[i]][yy+yyy[i]]){
counts[zz+zzz[i]][xx+xxx[i]][yy+yyy[i]]=step+;
Node ttt;
ttt.x=xx+xxx[i];
ttt.y=yy+yyy[i];
ttt.z=zz+zzz[i];
ttt.step=step+;
Q.push(ttt);
}
}
}
}
return counts[endz][endx][endy];//返回终点距离 }
int main(){
while(~scanf("%d%d%d",&l,&n,&m)&&l&&n&&m){
for(int i=;i<=l;i++){
for(int j=;j<=n;j++){
for(int k=;k<=m;k++){
cin>>map1[i][j][k];
if(map1[i][j][k]=='S'){
startz=i;
startx=j;
starty=k;
}
if(map1[i][j][k]=='E'){
endz=i;
endx=j;
endy=k;
}
}
}
}
int ans=BFS(startx,starty,startz);
if(ans==)
printf("Trapped!\n");
else
printf("Escaped in %d minute(s).\n",ans);
} }

Dungeon Master的更多相关文章

  1. POJ 2251 Dungeon Master(3D迷宫 bfs)

    传送门 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 11 ...

  2. poj 2251 Dungeon Master

    http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  3. Dungeon Master 分类: 搜索 POJ 2015-08-09 14:25 4人阅读 评论(0) 收藏

    Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20995 Accepted: 8150 Descr ...

  4. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  5. UVa532 Dungeon Master 三维迷宫

        学习点: scanf可以自动过滤空行 搜索时要先判断是否越界(L R C),再判断其他条件是否满足 bfs搜索时可以在入口处(push时)判断是否达到目标,也可以在出口处(pop时)   #i ...

  6. Dungeon Master poj 2251 dfs

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

  7. POJ 2251 Dungeon Master(地牢大师)

    p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...

  8. BFS POJ2251 Dungeon Master

    B - Dungeon Master Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  9. POJ 2251 Dungeon Master (非三维bfs)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 55224   Accepted: 20493 ...

  10. POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索)

    POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索) Description You ar ...

随机推荐

  1. strace使用详解(转) 分类: shell ubuntu 2014-11-27 17:48 134人阅读 评论(0) 收藏

    (一) strace 命令    用途:打印 STREAMS 跟踪消息. 语法:strace [ mid sid level ] ... 描述:没有参数的 strace 命令将所有的驱动程序和模块中的 ...

  2. etrace跟踪Nginx代码+ FASTCGI

    http://blog.csdn.net/jianqiangchen/article/details/29175285 http://blog.csdn.net/jianqiangchen/artic ...

  3. QtXML 举例

    QT读取xml有2个方法 对于xml数据比较大的就要用QXmlStreamReader 对于数据比较小的就用QDomDocument,这个比较方便 我这里就是以QDomDocument为主要内容,讲解 ...

  4. ios--绘图介绍

    iOS–绘图介绍 绘制图像的三种方式 一. 子类化UIView,在drawRect:方法画图 执行方法时,系统会自行创建画布(CGContext),并且讲画布推到堆栈的栈顶位置 执行完毕后,系统会执行 ...

  5. shell入门之expr的使用 分类: 学习笔记 linux ubuntu 2015-07-10 14:59 76人阅读 评论(1) 收藏

    在expr中加减乘除的使用,脚本如下: #!/bin/sh #a test about expr v1=`expr 5 + 6` echo "$v1" echo `expr 3 + ...

  6. javascript 高级程序设计(二)-在html中使用javascript

    <script> async 可选 charset 可选 defer 可选 language 已废弃 src 可选 type 可选

  7. UVA - 11572 Unique Snowflakes

    /* STLsort离散化==T 手工sort离散化==T map在线==T map离线处理c==A 240ms */ #include<cstdio> #include<map&g ...

  8. C# 内存管理优化畅想(三)---- 其他方法&结语

    前两篇文章提出的优化方法,都是不需要修改源代码的,而是在CLR或JIT层面进行自动优化的.但本文中提出的优化方法则需要引入新的语法,开发者只有在源代码中使用了这些新语法,才会获得优化. 1. 允许对象 ...

  9. Java_Activiti5_菜鸟也来学Activiti5工作流_之JUnit单元测试(四)

    /**ActivitiSpringJuinitTest.java * author : 冯孟活 ^_^ * dates : 2015年9月2日 下午2:16:54 * class : activiti ...

  10. 什么是html,什么是php

    学了这么长时间的网站建设,好像对这两个概念说以来还是语无伦次的,所以就来写一写了.html是什么呢,官方解释:超文本标记语言,超文本就是指页面可以包含图片,连接等非文字元素.超文本标记语言也是一种规范 ...