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的房间里有一个箱子和一个搬运工,搬运工的工作就是把箱子推到指定的位置,注意,搬运工只能推 ...
随机推荐
- samtools 的应用
1)sam转bam samtools view -bS in.sam > in.bam -b 意思使输出使BAM format -S 意思使输入使SAM,如果@SQ 缺剩, 要写-t
- CSS中的各种width(宽度)
一 window对象的innerWidth.outerWidth innerWidth是可用区域的宽度(内容区 + 滚动条) outerWidth是浏览器窗口的宽度(可用区域的宽度+审查元素区域的宽度 ...
- anaconda+theano+keras手写字符识别新版
标题介绍运行环境了win7 看网上好多keras识别minist 但是一般由于版本问题,无法直接用,,,这里还要特别感谢keras中文文档作者(三当家SCP).教程整的非常好.还有就是最好你在安装an ...
- Java 深浅拷贝
2016-07-02 1深拷贝:不仅拷贝对象,而且对象所引用地址的内容一块拷贝.改变一个对象的某个属性,并不影响另一个对象所引用的内容. 2浅拷贝:仅拷贝对象本身,并不对所引用(所指的)内容进行拷贝, ...
- [leetcode]124. Binary Tree Maximum Path Sum二叉树最大路径和
Given a non-empty binary tree, find the maximum path sum. For this problem, a path is defined as any ...
- 18-javaweb-ssm 开发中错误总结
由于web课设于是,写了几天的javaweb,在写的过程中总会遇到奇奇怪怪的一些bug, 一般都得花很多时间解决. 但是解决多了,后面碰到类似的简单多了. 总结下: 一.前端错误: 1.js错误,看前 ...
- php 使用PHPExcel 导出数据为Excel
<?php require_once 'PHPExcel/Classes/PHPExcel.php'; /** * 导出数据为Excel * @param array $fieldArr 标题数 ...
- Step1-有序顺序表
#include<stdio.h> #define N 100 typedef struct jcb{ ]; int arrtime; int reqtime; }jcb; jcb job ...
- Codeforces 599C. Day at the Beach 模拟
Day at the Beach time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- vue-route 路由传参的使用
1 router/index.js 中的定义 { path: '/product', component: ProductIndex, meta: { requiredAuth: true, }}, ...