3D dungeon

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
 
描述
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的更多相关文章

  1. NYOJ 353 3D dungeon 【bfs】

    题意:给你一个高L长R宽C的图形.每个坐标都能够视为一个方格.你一次能够向上.下.左,右,前,后任一方向移动一个方格, 可是不能向有#标记的方格移动. 问:从S出发能不能到达E,假设能请输出最少的移动 ...

  2. 3D dungeon

    算法:广搜: 描述 You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is comp ...

  3. NYOJ353 3D dungeon 【BFS】

    3D dungeon 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 You are trapped in a 3D dungeon and need to find ...

  4. NYOJ--353--bfs+优先队列--3D dungeon

    /* Name: NYOJ--3533D dungeon Author: shen_渊 Date: 15/04/17 15:10 Description: bfs()+优先队列,队列也能做,需要开一个 ...

  5. POJ 2251 Dungeon Master(3D迷宫 bfs)

    传送门 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 11 ...

  6. poj 2251 Dungeon Master

    http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  7. Dungeon Master 分类: 搜索 POJ 2015-08-09 14:25 4人阅读 评论(0) 收藏

    Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20995 Accepted: 8150 Descr ...

  8. Dungeon Master bfs

    time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u POJ 2251 Descriptio ...

  9. 暑假集训(1)第三弹 -----Dungeon Master(Poj2251)

    Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...

随机推荐

  1. 深入了解overflow

    1.如果overflow-x与overflow-y值不同   其中一个赋值为visiable,另一个赋值scroll/auto/hidden,那么visiable会重置为auto 2.overflow ...

  2. linux扩展lvm磁盘

    env: centos 6.5 x64 hyper-v虚拟机 这个方法可以在当前运行的系统中扩展root磁盘 详细步骤 之前想创建的一个虚拟机的磁盘空间不够用了,所以想扩容一下磁盘. 正好使用的时候是 ...

  3. MVC中Area的使用

    1.Area是什么? MVC 2 中引进了区域的概念,它允许将模型,视图和控制器分成单独的功能节点,换句话说,可以在大型复杂的网站中建立几个区域(模块),每一个区域都有Model,View,Contr ...

  4. 如何写一个像btgoogle一样的12306泄露数据查询

    demo地址:http://www.btgoogle.com/12306/ 圣诞节,12306送给了我们一个大礼物.大约 14w的数据泄露, 看网上都沸沸扬扬的.开始也准备找一个数据库来看看,随后,我 ...

  5. Poco库之XML操作

    平台ubuntu14.04LTS     Poco版本:Poco1.6.1 #include <Poco/DOM/Text.h>#include <Poco/DOM/Element. ...

  6. linq any()方法实现sql in()方法的效果

    public IQueryable<Vsec009ComSecComp> QueryList(Sec009ComSecCompQueryCondition condition) { var ...

  7. 服务器慢 mysql-bin.000001文件占满磁盘的原因与解决

    发现 VPS 服务器上的网站反应超级慢,简单的重启.重启各主要服务,发现mysql 的反应极其不正常. 一方面是问题,这与站点访问量有关.开始时从mysql 的配置文件 my.cnf 考虑,但志文工作 ...

  8. 在 IIS MIME 类型中添加 md 扩展名

    最近在了解 Knowledge Base (知识库)的内容,对两个平台比较感兴趣,一个是 Raneto,一个是 MDwiki,两者都是使用md文件作为内容存储. 需要注意的是,使用IIS部署网站后,需 ...

  9. tomcat https 配置

    以前基本上笔者对于安全性考虑的并不多,最近因为saas平台要开始逐渐推广,所以需要开始逐渐加强xss/crsf/https等措施以避免潜在的安全性风险.本文简单的记录下tomcat下https的配置. ...

  10. UIApplication 常用方法

    下面是这个类的一些功能:1.设置icon上的数字图标 //设置主界面icon上的数字图标,在2.0中引进, 缺省为0 [UIApplicationsharedApplication].applicat ...