nyoj 353 3D dungeon
3D dungeon
- 描述
- 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?
- 输入
- 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. - 输出
- 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! - 样例输入
-
3 4 5
S....
.###.
.##..
###.# #####
#####
##.##
##... #####
#####
#.###
####E 1 3 3
S##
#E#
### 0 0 0 - 样例输出
-
Escaped in 11 minute(s).
Trapped! 还是感觉广搜比深搜简单点#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
#define MAX 35
using namespace std;
int n,m,k;
int x1,x2,y1,y2,z1,z2;
char map[MAX][MAX][MAX];
int vis[MAX][MAX][MAX];
struct node
{
int x,y,z,step;
friend bool operator < (node a,node b)
{
return a.step>b.step;
}
};
void bfs()
{
int i,j;
int move[6][3]={0,0,1,0,0,-1,0,1,0,0,-1,0,1,0,0,-1,0,0};
priority_queue<node>q;
node beg,end;
beg.x=x1;
beg.y=y1;
beg.z=z1;
beg.step=0;
q.push(beg);
vis[x1][y1][z1]=1;
while(!q.empty())
{
end=q.top();
q.pop();
if(end.x==x2&&end.y==y2&&end.z==z2)
{
printf("Escaped in %d minute(s).\n",end.step);
return ;
}
for(i=0;i<6;i++)
{
beg.x=end.x+move[i][0];
beg.y=end.y+move[i][1];
beg.z=end.z+move[i][2];
if(!vis[beg.x][beg.y][beg.z]&&0<=beg.x&&beg.x<n&&0<=beg.y&&beg.y<m&&beg.z>=0&&beg.z<k&&map[beg.x][beg.y][beg.z]!='#')
{
map[beg.x][beg.y][beg.z]='#';
beg.step=end.step+1;
q.push(beg);
}
}
}
printf("Trapped!\n");
}
int main()
{
int i,j,t,s;
while(scanf("%d%d%d",&n,&m,&k)&&n!=0&&m!=0&&k!=0)
{
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%s",map[i][j]);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
for(t=0;t<k;t++)
{
if(map[i][j][t]=='S')
{
x1=i;y1=j;z1=t;
}
if(map[i][j][t]=='E')
{
x2=i;y2=j;z2=t;
}
}
}
}
memset(vis,0,sizeof(vis));
bfs();
}
return 0;
}
nyoj 353 3D dungeon的更多相关文章
- NYOJ 353 3D dungeon 【bfs】
题意:给你一个高L长R宽C的图形.每个坐标都能够视为一个方格.你一次能够向上.下.左,右,前,后任一方向移动一个方格, 可是不能向有#标记的方格移动. 问:从S出发能不能到达E,假设能请输出最少的移动 ...
- 3D dungeon
算法:广搜: 描述 You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is comp ...
- NYOJ353 3D dungeon 【BFS】
3D dungeon 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描写叙述 You are trapped in a 3D dungeon and need to find ...
- NYOJ--353--bfs+优先队列--3D dungeon
/* Name: NYOJ--3533D dungeon Author: shen_渊 Date: 15/04/17 15:10 Description: bfs()+优先队列,队列也能做,需要开一个 ...
- 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 ...
- Dungeon Master bfs
time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u POJ 2251 Descriptio ...
- 暑假集训(1)第三弹 -----Dungeon Master(Poj2251)
Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...
随机推荐
- (jQuery 插件)封装容器的表单为json对象
下面代码可以把一个页面容器中的表单元素封装成一个json对象. (function($){ $.fn.serializeObject=function(){ var inputs=$(this).fi ...
- php 商务网站购物车联动地址
数据表如下: CREATE TABLE IF NOT EXISTS `china` (`region_id` smallint(5) unsigned NOT NULL, `parent_id` s ...
- mysqli扩展库操作mysql数据库
配置环境 配置php.ini文件让php支持mysqli扩展库 extension=php_mysqli.dll 建库建表 详见博客 “mysql扩展库操作mysql数据库” 查询数据库 <?p ...
- Yii 权限分级式访问控制实现(非RBAC法)
以下由我们在信易网络公司开发项目的时候终结出的一些经验 主要参考资料:yii官网http://www.yiiframework.com/wiki/60/yii framework 提供了2套权限访问系 ...
- C语言学习总结(一) 基本语法
第一章--C语言的基本概念 丹尼斯 里奇 一.什么是C语言? 定义:是一个面向过程的计算机高级语言--不需要任何运行环境便能运行的程序语言: 发展:目前是C11 (K&R C—> ...
- 点评VHDL语言
(1)VHDL的描述风格及语法十分类似于一般的计算机高级语言,但是它是一种硬件描述语言.学好VHDL的关键是充分理解VHDL语句和硬件电路的关系.编写VHDL,就是在描述一个电路,我们写完一段程序后, ...
- C#开发攀爬集锦
工具使用 Files has invalid value "<<<<<<< .mine". Illegal characters in p ...
- SQL Server 2012 Features
SQL SQL Server 2012 新增加的几个函数: SELECT CONVERT (INT, 'Angkor-216.00') 直接报错 SELECT TRY_CONVERT(INT, 'SS ...
- 数据结构练习 02-线性结构3. Pop Sequence (25)
Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and p ...
- Mozilla公布WebVR API标准草案
随着信息技术的迅速发展,虚拟现实(Virtual Reality,VR)技术在近些年不断完善,其应用范围也变得十分广泛.为了搭建逼真的虚拟场景,VR技术一般都需要用到大量精美的图像和复杂的动作.因此, ...