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
- 3 4 5
- 样例输出
-
- 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;
- }
- Escaped in 11 minute(s).
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 ...
随机推荐
- Visual Studio2012中搭建WCF项目
分布式系统:指在系统与系统之间进行通信,系统不再是孤立的,例如:淘宝查看物流信息,或是hao123的天气预报,这些可能都是用的别的系统的web方法. 1.创建空的解决方案 2.新建项目-WCF服务库项 ...
- jquery中onclick内$(this)指向
jquery中onclick=”fn”中$(this)所代表的对象 js方法 function qiehuan(){ var src = $(this).attr(“data”); alert($(t ...
- JS获取IP、MAC和主机名的五种方法
javascript获取客户端IP的小程序,下面的代码是我在所有windowsNT5.0及以上的系统上都测试通过的,喜欢的朋友可以收藏下.今天在搞JS(javascript)获取客户端IP的小程序,上 ...
- Android App资源的查找过程分析
Android资源管理框架实际就是由AssetManager和Resources两个类来实现的.其中,Resources类可以根据ID来查找资源,而AssetManager类根据文件名来查找资源.事实 ...
- WPF中将四个数字字符串值(比如:"10,10,300,300")转为Rect
RectConverter rectConverter = new RectConverter(); string parseString = viewportEntry.Text; if (pars ...
- C#——System.Diagnostics.Process.Start的妙用
我们经常会遇到在Winform或是WPF中点击链接或按钮打开某个指定的网址, 或者是需要打开电脑中某个指定的硬盘分区及文件夹, 甚至是"控制面板"相关的东西, 那么如何做呢? 答案 ...
- vs2013调试崩溃,重启电脑依旧崩溃
如果大家遇到 VS断点调试程序崩溃的问题,可以排查是不是有这个问题 VSx新安装了插件 点击工具---扩展和更新 禁用最新安装的程序 一般就没有问题了
- 数据采集服务提供商,ip提供商 里面有些不错的基础数据
http://user.qzone.qq.com/1649677458 这家公司的爬虫应该挺牛的 !@#!#!~#¥¥¥@@http://www.site-digger.com/
- Eclipse里初次使用Maven注意问题
在Eclipse里初次使用Maven,右键project->add dependency, 发现search不管用,这时候需要按照以下步骤操作: Goto "Preferences - ...
- uva 12526 - Cellphone Typing
字典树,可惜比赛的时候有两句话写倒了: 害得我调了一个小时: 今天不宜做题 = = 代码: #include<cstdio> #include<cstring> #define ...