HDU1253 胜利大逃亡(BFS) 2016-07-24 13:41 67人阅读 评论(0) 收藏
胜利大逃亡
Problem Description
魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示成A个B*C的矩阵,刚开始Ignatius被关在(0,0,0)的位置,离开城堡的门在(A-1,B-1,C-1)的位置,现在知道魔王将在T分钟后回到城堡,Ignatius每分钟能从一个坐标走到相邻的六个坐标中的其中一个.现在给你城堡的地图,请你计算出Ignatius能否在魔王回来前离开城堡(只要走到出口就算离开城堡,如果走到出口的时候魔王刚好回来也算逃亡成功),如果可以请输出需要多少分钟才能离开,如果不能则输出-1.

Input
特别注意:本题的测试数据非常大,请使用scanf输入,我不能保证使用cin能不超时.在本OJ上请使用Visual C++提交.
Output
Sample Input
1
3 3 4 20
0 1 1 1
0 0 1 1
0 1 1 1
1 1 1 1
1 0 0 1
0 1 1 1
0 0 0 0
0 1 1 0
0 1 1 0
Sample Output
11
____________________________________________________________________
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
int map[55][55][55];
int vis[55][55][55];
int l,m, n, t;
int dir[6][3] = { { -1, 0, 0 }, { 1, 0, 0 }, { 0, -1, 0 }, { 0, 1, 0 }, { 0, 0, -1 }, { 0, 0, 1 } }; struct node
{
int x, y,z ,cnt;
};
bool cheak(int i, int j, int k)
{
if (i < 1 || i > l || j < 1 || j > m || k < 1 || k > n || map[i][j][k] != 0)
return 0;
else
return 1;
}
int bfs()
{
queue<node>q;
node f, p;
f.x = 1;
f.y = 1;
f.z = 1;
f.cnt = 0;
q.push(f);
vis[1][1][1] = 1;
while (!q.empty())
{
f = q.front();
q.pop();
if (f.x == l&&f.y == m&&f.z == n&&f.cnt<=t)
{
return f.cnt;
}
for (int i = 0; i < 6; i++)
{
p.x = f.x + dir[i][0];
p.y = f.y + dir[i][1];
p.z = f.z + dir[i][2]; if (!vis[p.x][p.y][p.z]&&cheak(p.x, p.y, p.z))
{
p.cnt = f.cnt + 1;
if (p.cnt>t)
continue;
vis[p.x][p.y][p.z] = 1;
q.push(p);
}
}
}
return -1; }
int main()
{
int o;
while (~scanf("%d", &o))
{
while (o--)
{
memset(vis, 0, sizeof(vis));
scanf("%d%d%d%d", &l, &m, &n, &t);
for (int i = 1; i <= l; i++)
for (int j = 1; j <= m; j++)
for (int k = 1; k<= n; k++)
scanf("%d", &map[i][j][k]);
int ans = bfs();
printf("%d\n", ans);
}
}
return 0; }
HDU1253 胜利大逃亡(BFS) 2016-07-24 13:41 67人阅读 评论(0) 收藏的更多相关文章
- C#期末大作业 消消乐 2017-06-01 18:11 275人阅读 评论(0) 收藏
邻近期末,忙于刷题之余意识到期末大作业来不及了,匆匆赶下了作业,虽说做的很是粗糙,但完全原创的 下载链接 https://pan.baidu.com/s/1cCNLr4 大体的做大约3天完成了: 第一 ...
- HDU1175 连连看(bfs) 2016-07-24 13:27 115人阅读 评论(0) 收藏
连连看 Problem Description "连连看"相信很多人都玩过.没玩过也没关系,下面我给大家介绍一下游戏规则:在一个棋盘中,放了很多的棋子.如果某两个相同的棋子,可以通 ...
- Android 应用中十大常见 UX 错误 分类: H1_ANDROID 2013-09-21 13:59 404人阅读 评论(0) 收藏
转载自:http://www.apkbus.com/android-5661-1.html 摘要: Android 开发者关系团队每天都会试用无数的 App 或者受到无数的开发者发来的请求评测的 Ap ...
- HDU1253 胜利大逃亡 BFS
胜利大逃亡 Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submiss ...
- Hdu 1429 胜利大逃亡(续) 分类: Brush Mode 2014-08-07 17:01 92人阅读 评论(0) 收藏
胜利大逃亡(续) Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Subm ...
- Hdu1429 胜利大逃亡(续) 2017-01-20 18:33 53人阅读 评论(0) 收藏
胜利大逃亡(续) Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Subm ...
- HDU1072 Nightmare(BFS) 2016-07-24 14:02 40人阅读 评论(0) 收藏
Nightmare Problem Description Ignatius had a nightmare last night. He found himself in a labyrinth w ...
- Hdu3549 Flow Problem 2017-02-11 16:24 58人阅读 评论(0) 收藏
Flow Problem Problem Description Network flow is a well-known difficult problem for ACMers. Given a ...
- HDU1254 推箱子(BFS) 2016-07-24 14:24 86人阅读 评论(0) 收藏
推箱子 Problem Description 推箱子是一个很经典的游戏.今天我们来玩一个简单版本.在一个M*N的房间里有一个箱子和一个搬运工,搬运工的工作就是把箱子推到指定的位置,注意,搬运工只能推 ...
随机推荐
- a,b = b,a 换值问题
a = "hello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhe ...
- 数据预处理之独热编码(One-Hot Encoding)(转载)
问题由来 在很多机器学习任务中,特征并不总是连续值,而有可能是分类值. 例如,考虑一下的三个特征: ["male", "female"] ["from ...
- conductor APIs
任务和工作流元数据 端点 描述 输入 GET /metadata/taskdefs 获取所有任务定义 N / A GET /metadata/taskdefs/{taskType} 检索任务定义 任务 ...
- 用R包来下载sra数据
1)介绍 我们用SRAdb library来对SRA数据进行处理. SRAdb 可以更方便更快的接入 metadata associated with submission, 包括study, sa ...
- java 元数据
什么是元数据? 元数据是指用来描述数据的数据,更通俗一点,就是描述代码间关系,或者代码与其他资源(例如数据库表)之间内在联系的数据.在一些技术框架,如struts.EJB.hibernate就不知不觉 ...
- Scriptable Object
[Scriptable Object] ScriptableObject 是一个可继承的Class,适用于存储大数据的情形. Consider for example that you have m ...
- 10.9zuoye
public class fulei { public fulei() { System.out.println("欢迎使用海尔"); } public String Pinpai ...
- 122. Best Time to Buy and Sell Stock II (Array;Greedy)
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- 【校招面试 之 C/C++】第7题 C++构造函数不能是虚函数的原因
1.虚拟函数调用只需要“部分的”信息,即只需要知道函数接口,而不需要对象的具体类型.但是构建一个对象,却必须知道具体的类型信息.如果你调用一个虚拟构造函数,编译器怎么知道你想构建是继承树上的哪种类型呢 ...
- VS 窗体大小
锁定窗体大小,就是鼠标停在窗口边框的时候,不能拖动来改变它的大小…… 有两种方法: 1.可以把Form的属性 FormborderStyle 后面选择 FixedDialog 2.或者把Form窗体的 ...