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的房间里有一个箱子和一个搬运工,搬运工的工作就是把箱子推到指定的位置,注意,搬运工只能推 ...
随机推荐
- tensor flow 安装
http://blog.csdn.net/nxcxl88/article/details/52704877?locationNum=13 安装后,一定要运行这句话后 $ source activa ...
- C语言实现24点程序
一.简介 本程序的思想和算法来自于C语言教材后的实训项目,程序通过用户输入四个整数计算出能够通过加减乘除得到数字24的所有表达式,程序的设计有别于一般通过穷举实现的方式,效率得到提高.算法介绍如下: ...
- "诗词大闯关"调查过程心得体会
为了充分满足客户需求来更好地完成我们的项目--"诗词大闯关",我们根据项目内容,制定了调查表.我们小组以网上问卷调查的形式制作了调查表,并收集了122份有效的问卷调查表. 通过这次 ...
- Graph Coloring I(染色)
Graph Coloring I https://www.nowcoder.com/acm/contest/203/J 题目描述 修修在黑板上画了一些无向连通图,他发现他可以将这些图的结点用两种颜色染 ...
- [leetcode]415. Add Strings字符串相加
Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2 ...
- 15-matlab矩阵运用
from scipy.spatial import Delaunay from mpl_toolkits.mplot3d import Axes3D import numpy as np import ...
- iframe父窗口和子窗口之间的调用
1>父窗口获取子窗口 js方法 document.getElementById('if1').contentWindow.document: window.frames["if1&qu ...
- 在windows系统下安装oracle 11g
oracle 11g 安装在windows server 2012 系统下. 最近,需要配置数据库,要求在windows操作系统下,安装oracle 11g 数据库,因为以前没有安装过,所以成功后, ...
- Loadrunner12.5-录制http://www.gw.com.cn/网页时提示“SSL身份验证失败”错误,这是为什么呢?
问题:LR产品,录制http://www.gw.com.cn/ 网页时提示下图错误,这是为什么呢? 请在如下recording options中选择正确的SSL版本,再进行录制. 注:如何确定那个SS ...
- 用递归方法求 n!
#include <iostream> using namespace std; #define LL long long LL fac(int n) { LL f; || n == ) ...