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. U盘安装centos 6.4教程(总算是弄好了

    参考:http://blog.chinaunix.net/uid-27666459-id-3342477.html http://www.linuxidc.com/Linux/2011-05/3569 ...

  2. JAVA中的static修饰的方法不能被重写

    可以重写静态方法,但重写后的静态方法不支持多态. 其实static根本就没有重写之说.static方法引用的时候应该用类名来引用,而不是对象.同时static方法不参与继承,所以在继承体系里面也不存在 ...

  3. 关于text-align无法居中的问题

    昨天项目,一直出现一个无法居中的问题,最后发现竟然是text-align的问题,才发现自己对text-align的理解还是不够透彻,于是在此再举例分析下. css中的元素一共有三类:块元素.行内块和内 ...

  4. 重载,重写和super

    1.重载的概念:----->在同一个类中,允许存在同名函数,但它们的参数个数或者参数类型不同即可.public static void main(String[] args){System.ou ...

  5. iBatis 的删除一条记录

    Student.xml 设置删除参数的类型,可以是一个对象的 <delete id="delStudent" parameterClass="int" & ...

  6. HTML5 WebAudioAPI-实例(二)

    简单播放实例1: var url='../content/audio/海阔天空.mp3'; if (!window.AudioContext) { alert('您的浏览器不支持AudioContex ...

  7. 自己动手写控件(模仿mvc htmlhelper的类)

    自定义helper类,要求命名空间在 System.Web.Mvc之下,要求,静态类,静态方法,特殊生成对应html的返回字段, 传递Htmlhleper,返回特定类型 返回值是MvcHtmlStri ...

  8. SQL Server死锁日志各字段含义

    使用跟踪标记 1204 --打开跟踪标记 DBCC TRACEON (1204,-1) --关闭跟踪标记 DBCC TRACEOFF (1204,-1) 处于死锁状态时,跟踪标记 1204 在等待的线 ...

  9. java Web Services搭建环境时遇到的各种问题,记录一下。 java.lang.OutOfMemoryError: PermGen space,org/apache/struts2/util/ObjectFactoryDestroyable

    情况:在同一个,myEclipes 下加载俩个项目,一个seriver端,一个client端. 必备: myEclipes    ,apache-tomcat-7.0.42,apache-tomcat ...

  10. 设置css三种方法的优先级

    有的小伙伴问了,如果有一种情况:对于同一个元素我们同时用了三种方法设置css样式,那么哪种方法真正有效呢?在下面代码中就出现了这种情况 1.使用内联式CSS设置“超酷的互联网”文字为粉色. 2.然后使 ...