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 ...
随机推荐
- C# Thread多线程学习
自我学习理解:一个程序中包括多个进程,每个进程包括多个线程,多个线程可同时做不同的事情(说是同时,但它是交换执行的,人感觉像是同时罢了). 优点:提高CPU的使用率. 线程同步:同步就是指一个线程要等 ...
- demo——06弹性和制作骰子
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 破解https和https原理
http://blog.csdn.net/cch5487614/article/details/6364711 http://www.jb51.net/network/68135.html
- Linux命令 &与&&的作用
1.ls &表示后台服务 2.ls && ll 表示前者执行成功,执行后台命令
- 转 mysql 中sql 语句查询今天、昨天、7天、近30天、本月、上一月 数据
转自 http://blog.csdn.net/ve_love/article/details/19685399
- block的用法和循环引用
一.block在OC中的用法可以分为大概一下几种. 1>用于成员属性,保存一段代码,可以替代代理传值. 比如说,创建一个ViewController控制器,点击屏幕就跳转到ModalViewCo ...
- C++ 11 笔记 (六) : 随机数
以前生成一个随机数都是这样: srand(time(NULL)); rand(); 在C++11中,标准库中增加了随机数引擎 std::default_random_engine 这个好东西,然后我们 ...
- maven的安装,maven库配置和Eclipse插件的安装
maven的安装,maven库配置和Eclipse插件的安装 1.下载并解压maven 2.配置环境变量 3.配置maven配置文件 1.下载链接 Downloading Apache Maven 2 ...
- LightOj_1408 Batting Practice
题目链接 题意: 击球训练中, 你击中一个球的概率为p,连续击中k1个球, 或者连续击空k2个球, 则训练结束. 求结束训练所击球次数的期望. 思路: 设f[x]为连续击中x个球, 距离结束训练所需要 ...
- BZOJ 1574: [Usaco2009 Jan]地震损坏Damage
Description 农夫John的农场遭受了一场地震.有一些牛棚遭到了损坏,但幸运地,所有牛棚间的路经都还能使用. FJ的农场有P(1 <= P <= 30,000)个牛棚,编号1.. ...