博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj2251 Dungeon Master
阅读量:6270 次
发布时间:2019-06-22

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

Dungeon Master

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 33157 Accepted: 12711
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 5S.....###..##..###.#############.####...###########.#######E1 3 3S###E####0 0 0

Sample Output

Escaped in 11 minute(s).

Trapped!

第二次做,找了一个小时bug,生无可恋

题意:三维迷宫找出口
错误点:一:步数不是now.teap++,而是now.teap+1;
二:定义清0是#define mem(a,b) memset(a,b,sizeof(a))

#include 
#include
#include
#include
#include
using namespace std;#define mem(a,b) memset(a,b,sizeof(a))char a[35][35][35];int vis[35][35][35];int sh,si,sj;int eh,ei,ej;int h,n,m;int to[6][3]={ 1,0,0, -1,0,0, 0,1,0, 0,-1,0, 0,0,1, 0,0,-1};struct node{ int hh,ii,jj; int step;};int bfs(int sh,int si,int sj){ mem(vis,0); vis[sh][si][sj]=1; node now,next; queue
s; now.hh=sh,now.ii=si,now.jj=sj,now.step=0; s.push(now); while(!s.empty()) { now=s.front(); if(now.hh==eh&&now.ii==ei&&now.jj==ej) { return now.step; break; } for(int i=0; i<6; i++) { int H=now.hh+to[i][0],X=now.ii+to[i][1],Y=now.jj+to[i][2]; if(H>=0&&H
=0&&X
=0&&Y
0) printf("Escaped in %d minute(s).\n",ans); else printf("Trapped!\n"); } return 0;}

转载于:https://www.cnblogs.com/zxy160/p/7215111.html

你可能感兴趣的文章
jquery的图片轮播 模板类型
查看>>
C# 获取文件名及扩展名
查看>>
Web安全学习计划
查看>>
输出有序数组的连续序列范围
查看>>
zinnia项目功能分析
查看>>
windows cmd for paramiko
查看>>
SQL经典面试题集锦
查看>>
View学习(一)-DecorView,measureSpec与LayoutParams
查看>>
色彩力量!21款你应该知道的优秀品牌设计
查看>>
SDUT 3503 有两个正整数,求N!的K进制的位数
查看>>
【.Net】C# 根据绝对路径获取 带后缀文件名、后缀名、文件名、不带文件名的文件路径...
查看>>
Redis常用命令速查 <第二篇>
查看>>
CSS规范
查看>>
使用FastDateFormat来代替JDK自带的DateFormat
查看>>
Python爬虫从入门到放弃(十六)之 Scrapy框架中Item Pipeline用法
查看>>
Android源代码解析之(三)--&gt;异步任务AsyncTask
查看>>
(zhuan) 自然语言处理中的Attention Model:是什么及为什么
查看>>
C#中使用RabbitMQ收发队列消息
查看>>
Hadoop1.2.1 全然分布式集群搭建实操笔记
查看>>
第三百二十七节,web爬虫讲解2—urllib库爬虫—基础使用—超时设置—自动模拟http请求...
查看>>