Dungeon Master POJ - 2251 (搜索)
Dungeon Master
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
where x is replaced by the shortest time it takes to escape.
Sample Input 3 4 5 Sample Output Escaped in 11 minute(s). Source |
题意:给你一个多维的迷宫,问能不能可以从起点走到终点,可以上下穿梭层数,也可以东南西北走,都是一秒一个单位,可以到终点就输出步数,不可以就输出那句话
思路:其实和普通的二维迷宫差不多,就是多了一个层数,也就是多了两个方向(上下层数)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
using namespace std;
#define INF 0x3f3f3f3f
#define eps 1e-10
#define PI acos(-1.0)
#define ll long long
int const maxn = ;
const int mod = 1e9 + ;
int gcd(int a, int b) {
if (b == ) return a; return gcd(b, a % b);
} char map[maxn][maxn][maxn];
int vis[maxn][maxn][maxn];
int k,n,m,sx,sy,sz,ex,ey,ez;
int dir[][]={{,,},{,,-},{,,},{,-,},{,,},{-,,}}; struct node
{
int x,y,z,step;
};
int check (int x,int y,int z)
{
if(x< || y< || z< || x>=k || y>=n || z>=m)
return ;
else if(map[x][y][z]=='#')
return ;
else if(vis[x][y][z])
return ;
return ;
} int bfs()
{
node a,next;
queue<node>que;
a.x=sx; a.y=sy; a.z=sz;
a.step=;
vis[sx][sy][sz]=;
que.push(a);
while(!que.empty())
{
a=que.front();
que.pop();
if(a.x == ex && a.y == ey && a.z == ez)
return a.step;
for(int i=;i<;i++)
{
next=a;
next.x=a.x+dir[i][];
next.y=a.y+dir[i][];
next.z=a.z+dir[i][];
if(check(next.x,next.y,next.z))
continue;
vis[next.x][next.y][next.z]=;
next.step=a.step+;
que.push(next); }
}
return ; } int main()
{
while(~scanf("%d %d %d",&k,&n,&m))
{
if(k== && n== && m==)
break;
for(int i=;i<k;i++)
{
for(int j=;j<n;j++)
{
scanf("%s",map[i][j]);
for(int r=;r<m;r++)
{
if(map[i][j][r]=='S')
{
sx=i;sy=j;sz=r;
}
else if(map[i][j][r]=='E')
{
ex=i;ey=j;ez=r;
}
}
}
}
memset(vis,,sizeof(vis));
int ans;
ans=bfs();
if(ans)
printf("Escaped in %d minute(s).\n",ans);
else
printf("Trapped!\n");
}
return ;
}
Dungeon Master POJ - 2251 (搜索)的更多相关文章
- Dungeon Master poj 2251 dfs
Language: Default Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16855 ...
- Dungeon Master POJ - 2251 [kuangbin带你飞]专题一 简单搜索
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- kuangbin专题 专题一 简单搜索 Dungeon Master POJ - 2251
题目链接:https://vjudge.net/problem/POJ-2251 题意:简单的三维地图 思路:直接上代码... #include <iostream> #include & ...
- (广搜)Dungeon Master -- poj -- 2251
链接: http://poj.org/problem?id=2251 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2137 ...
- Dungeon Master POJ - 2251(bfs)
对于3维的,可以用结构体来储存,详细见下列代码. 样例可以过,不过能不能ac还不知道,疑似poj炸了, #include<iostream> #include<cstdio> ...
- B - Dungeon Master POJ - 2251
//纯bfs #include <iostream> #include <algorithm> #include <cstring> #include <cs ...
- POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索)
POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索) Description You ar ...
- Dungeon Master 分类: 搜索 POJ 2015-08-09 14:25 4人阅读 评论(0) 收藏
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20995 Accepted: 8150 Descr ...
- poj 2251 搜索
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13923 Accepted: 5424 D ...
随机推荐
- 每次打开 excel2010 都要配置如何解决
遇到这种情况有以下几种解决方法 1.修改原有office启动名称 打开"C:/Program Files/Common Files/Microsoft Shared/OFFICE14/Off ...
- mysql主从复制之同步部分库表
这里以mariadb为例,和mysql一样的配置 系统:centos7 主服务器:192.168.0.1:3305(两台服务器都做过时间同步) 从服务器:192.168.0.2:3306(两台服务器都 ...
- Sandcastle Help File Builder 生成NET帮助文档
Sandcastle是微软提供的一个根据XML注释和DLL文件生成帮助文件的工具,目前是在CodePlex上的一个开源项目,可以去这里下载:Sandcastle Sandcastle生成的输出结果具有 ...
- 了解Unix进程(3)
fork() 系统调用可以创建新的进程.然后查看进程ID和父进程ID使用getpid()和getppid()函数. 使用C语言描述: #include <unistd.h> #includ ...
- 《web-Mail服务的搭建》
首先是搭建后台服务: 下载下面2个软件包 extmail-1.2.tar.gz extman-1.1.tar.gz 创建一个extsuite目录,固定格式 mkdir /var/www/extsuit ...
- windows 2012 r2 x64 安装IIS注意事项
详细安装可以参考下面; https://jingyan.baidu.com/article/93f9803f234eade0e46f559f.html 下面只说一些注意事项,如果项目要用到wcf 的话 ...
- cairo-dock天气位置代码
cairo-dock天气位置代码: 城市: 北京CHXX0008哈尔滨CHXX0046长春CHXX0010沈阳CHXX0119大连CHXX0019天津CHXX0133呼和浩特CHXX0249乌鲁木齐C ...
- JFrame 文本打印
package tools; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Font; import jav ...
- ngnix反向代理
https://blog.csdn.net/sherry_chan/article/details/79055211
- 3D向2D投影
http://blog.sina.com.cn/s/blog_536e0eaa0100jn7j.html