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 ...
随机推荐
- jasper_excel_sheet tab color
<property name="net.sf.jasperreports.export.xls.sheet.tab.color" value="#00FF00&qu ...
- chapter09
import java.io.File import java.nio.file._ import scala.collection.mutable.ArrayBuffer/** * Created ...
- Domain Model
VO(View Object):视图对象,用于展示层,它的作用是把某个指定页面(或组件)的所有数据封装起来. DTO(Data Transfer Object):数据传输对象,这个概念来源于J2EE的 ...
- @SessionAttribute使用详解
@SessionAttribute使用详解 @ModelAttribute注解作用在方法上或者方法的参数上,表示将被注解的方法的返回值或者是被注解的参数作为Model的属性加入到Model中,然后 ...
- 两个线程分别打印 1- 100,A 打印偶数, B打印奇数
package com.demo.thread; public class PrintNumber { private static Object lock = new Object(); priva ...
- strcpy、strncpy、strlen、memcpy、memset、strcat、strncat、strcmp、strncmp,strchr
1.strcpy #include<stdio.h> #include<assert.h> char *mystrcpy(char *dest, const char *src ...
- (转)在CentOS中修改中文字符集
虽然在实际工作环境下,Linux中不建议使用中文,但是如果一定要进行中文显示,尤其对于刚接触linux且英语基础不太好的人来说,那么本文具有一定的参考价值. 本文介绍在linux的shell环境下优化 ...
- matlab 打不开excel文件
方法论 excel的后缀为.xls, matlab是无法识别的, 需要将其另存为.xlsx文件格式 打开excel, 点击save as, 选中保存的文件格式是.xlsx即可
- 洛谷P4133 [BJOI2012]最多的方案(记忆化搜索)
题意 题目链接 求出把$n$分解为斐波那契数的方案数,方案两两不同的定义是分解出来的数不完全相同 Sol 这种题,直接爆搜啊... 打表后不难发现$<=1e18$的fib数只有88个 最先想到的 ...
- Vue.js(2.x)之插值
看了一些友邻写的文章,不少是基于1.0版本的,有些东西在2.x版本应该已经废除了(如属性插值.单次插值在2.x版本上运行根本不执行).对于不理解的东东,找起资料来就更麻烦了.不得不老老实实线下测试并整 ...