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的房间里有一个箱子和一个搬运工,搬运工的工作就是把箱子推到指定的位置,注意,搬运工只能推 ...
随机推荐
- ubuntu wifi连接不上或经常断网,重启就好 [ 转]
转自 http://blog.csdn.net/chinabing/article/details/47184093 问题描述:最近安装了win7和ubuntu 14.04.2双系统,每次进入ubun ...
- IDEA kotlin 配置
修改 idea 安装目录 bin 目录 下 idea.properties 文件修改idea.max.intellisense.filesize=50000 避免proto 生成的java文件不被 ...
- Hadoop 初始化系统
hadoop namenode -format 或者 hdfs namenode -format 2.执行hadoop sbin 目录下的 start-dfs.sh start-yarn.sh3.查看 ...
- dubbo-admin 管理平台
一.前言 dubbo的使用,其实只需要有注册中心,消费者,提供者这三个就可以使用了,但是并不能看到有哪些消费者和提供者,为了更好的调试,发现问题,解决问题,因此引入dubbo-admin.通过dubb ...
- MAVEN 引入外部JAR 包
MAVEN引入AXIS依赖的JAR包 在POM.XML中加入即可 <!-- axis 1.4 jar start --> <dependency> <groupId> ...
- 清理数据库errorlog
C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOGERRORLOGERRORLOG.1ERRORLOG.2ERRORLOG.3ERRORLO ...
- chrome input去除黄色背景色
input:-webkit-autofill { -webkit-box-shadow: 0 0 0px 1000px white inset; border: 1px solid #CCC!impo ...
- sqlserver 几种datatime的区别
参考文章1 smalldatetime 占4位精确到分钟.时间从1900.1.1到2079.6.6datetime占8位精确到毫秒.时间从1753.1.1到9999.12.31 参考文章2 datet ...
- centos7下创建mysql5.6多实例
一.mysql安装目录说明mysql5.6以二进制安装包安装在/data/mysql56下数据目录为/data/mysql56/data下配置文件为/etc/my.cnf下 二.多实例目录说明/mys ...
- tcl&redis安装
http://www.linuxfromscratch.org/blfs/view/cvs/general/tcl.html tcl http://redis.io/topics/quickstart