博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDOJ-三部曲一(搜索、数学)-1005-Dungeon Master
阅读量:5242 次
发布时间:2019-06-14

本文共 3371 字,大约阅读时间需要 11 分钟。

Dungeon Master

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 18   Accepted Submission(s) : 12
Problem Description
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid rock on all sides. 
Is an escape possible? If yes, how long will it take? 
 
Input
The input consists of a number of dungeons. Each dungeon description starts with a line containing three integers L, R and C (all limited to 30 in size).  L is the number of levels making up the dungeon.  R and C are the number of rows and columns making up the plan of each level.  Then there will follow L blocks of R lines each containing C characters. Each character describes one cell of the dungeon. A cell full of rock is indicated by a '#' and empty cells are represented by a '.'. Your starting position is indicated by 'S' and the exit by the letter 'E'. There's a single blank line after each level. Input is terminated by three zeroes for L, R and C.
 
Output
Each maze generates one line of output. If it is possible to reach the exit, print a line of the form 
Escaped in x minute(s).
where x is replaced by the shortest time it takes to escape.  If it is not possible to escape, print the line 
Trapped!
 
Sample Input
3 4 5
S....
.###.
.##..
###.#
 
#####
#####
##.##
##...
 
#####
#####
#.###
####E
 
1 3 3
S##
#E#
###
 
0 0 0
 
Sample Output
Escaped in 11 minute(s).
Trapped!
 
Source
PKU
 
 
 
又一道BFS水题,我发现我刷搜索水题很溜啊哈哈。。
 
 
#include
#include
using namespace std;char cube[31][31][31];bool sign[31][31][31]; int L,R,C;struct pos{ int l,r,c;};pos que[54000],beg;int step[54000];int BFS(){ int front=0,rear=1; que[0]=beg; sign[que[0].l][que[0].r][que[0].c]=true; while(front
=0&&!sign[que[front].l-1][que[front].r][que[front].c]&&cube[que[front].l-1][que[front].r][que[front].c]!='#') { que[rear]=que[front]; que[rear].l=que[front].l-1; sign[que[rear].l][que[rear].r][que[rear].c]=true; step[rear]=step[front]+1; if(cube[que[rear].l][que[rear].r][que[rear].c]=='E') return step[rear]; rear++; } if(que[front].l+1
=0&&!sign[que[front].l][que[front].r-1][que[front].c]&&cube[que[front].l][que[front].r-1][que[front].c]!='#') { que[rear]=que[front]; que[rear].r=que[front].r-1; sign[que[rear].l][que[rear].r][que[rear].c]=true; step[rear]=step[front]+1; if(cube[que[rear].l][que[rear].r][que[rear].c]=='E') return step[rear]; rear++; } if(que[front].r+1
=0&&!sign[que[front].l][que[front].r][que[front].c-1]&&cube[que[front].l][que[front].r][que[front].c-1]!='#') { que[rear]=que[front]; que[rear].c=que[front].c-1; sign[que[rear].l][que[rear].r][que[rear].c]=true; step[rear]=step[front]+1; if(cube[que[rear].l][que[rear].r][que[rear].c]=='E') return step[rear]; rear++; } if(que[front].c+1
>L>>R>>C&&(R+C+L)) { int i,j,k; memset(sign,false,sizeof(sign)); memset(step,0,sizeof(step)); for(i=0;i
>cube[i][j][k]; if(cube[i][j][k]=='S') { beg.l=i; beg.r=j; beg.c=k; } } } int ans=BFS(); if(ans==-1) cout<<"Trapped!"<

 

 

转载于:https://www.cnblogs.com/aljxy/p/3337585.html

你可能感兴趣的文章
Java内部类详解
查看>>
【hdu 1429】胜利大逃亡(续)
查看>>
图论-次短路求法
查看>>
What's New for Visual C# 6.0
查看>>
ExtJs学习笔记之ComboBox组件
查看>>
关于收费软件
查看>>
getopt_long
查看>>
TensorFlow MNIST CNN 代码
查看>>
javascript之Style物
查看>>
JSON跨域解决方案收集
查看>>
SSH框架整合总结
查看>>
图的深度优先遍历
查看>>
C# 之 提高WebService性能大数据量网络传输处理
查看>>
md5sum命令详解
查看>>
[bzoj1004] [HNOI2008] Cards
查看>>
原生HttpClient详细使用示例
查看>>
几道面试题
查看>>
Factory Design Pattern
查看>>
python中贪婪与非贪婪
查看>>
guava API整理
查看>>