Dungeon Master
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的更多相关文章
- POJ 2251 Dungeon Master(3D迷宫 bfs)
传送门 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 11 ...
- poj 2251 Dungeon Master
http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- Dungeon Master 分类: 搜索 POJ 2015-08-09 14:25 4人阅读 评论(0) 收藏
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20995 Accepted: 8150 Descr ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- UVa532 Dungeon Master 三维迷宫
学习点: scanf可以自动过滤空行 搜索时要先判断是否越界(L R C),再判断其他条件是否满足 bfs搜索时可以在入口处(push时)判断是否达到目标,也可以在出口处(pop时) #i ...
- Dungeon Master poj 2251 dfs
Language: Default Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16855 ...
- POJ 2251 Dungeon Master(地牢大师)
p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...
- BFS POJ2251 Dungeon Master
B - Dungeon Master Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- POJ 2251 Dungeon Master (非三维bfs)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 55224 Accepted: 20493 ...
- 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 ...
随机推荐
- Linux kernel驱动相关抽象概念及其实现 之“linux设备模型kobject,kset,ktype”
kobject,kset,ktype三个很重要的概念贯穿Linux内核驱动架构,特转载一篇博文: (转载自http://blog.csdn.net/gdt_a20/article/details/64 ...
- [Angular 2] Keynote: Lazy Routing -- NGCONF
So How to do lazy loading for router in Angular 2. The nomarl way to write a router in Angular 2: Yo ...
- etrace 跟踪 nginx之HTTP请求流程
curl 127.0.0.1 | | | \--ngx_epoll_process_events | | | | \--ngx_time_update | | | | | \--ngx_gmtime ...
- QTableWidget的使用和美工总结
基本外观设置 FriendTable->setFrameShape(QFrame::NoFrame); //设置边框 FriendTable->setHorizontalHeaderLa ...
- ios中从相册:相机中获取图片信息
ios中从相册/相机中获取图片信息 从相册中获取图片的信息 UIImagePickerController *imgPickView = [[UIImagePickerController alloc ...
- GOOGLE搜索從入門到精通V4.0
1,前言2,摘要3,如何使用本文4,Google簡介5,搜索入門6,初階搜索 6.1,搜索結果要求包含兩個及兩個以上關鍵字 6.2,搜索結果要求不包含某些特定資訊 6.3,搜索結果至少包含多個關鍵字中 ...
- Java基础知识强化之集合框架笔记25:Vector的特有功能
1. Vector的特有功能: (1)添加功能 public void addElement(Object obj) -- add() (2)获取功能 pu ...
- 【转载】ASP.NET支持多语言
ASP.NET 2.0中实现:1.使用工具自动生成本地化资源(LocalResources) 首先建立一个WEB工程,如图所示:双击Default.aspx,切换到[设计]视图,从工具箱里拖一个But ...
- 第三篇:python基础之编码问题
python基础之编码问题 python基础之编码问题 本节内容 字符串编码问题由来 字符串编码解决方案 1.字符串编码问题由来 由于字符串编码是从ascii--->unicode---&g ...
- mysql复习笔记
阅读目录 1.什么是SQL语句2.使用sql语句创建数据库和表3.创建数据表4.数据完整性约束5.四中基本字符类型说明6.SQL基本语句7.类型转换函数8.日期函数9.数学函数10.字符串函数11.联 ...