HDOJ 1253 胜利大逃亡(bfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1253
思路分析:因为问题需要寻找到达终点的最短的距离(最短的步数),即在状态转换图上需要找出层次最浅的的状态(A-1, B-1, C-1),
所以采用bfs更快能找出答案;另外,若采用dfs则比较困难,需要遍历所有的状态才能找出结果。
代码如下:
#include <cstdio>
#include <iostream> const int MAX_N = ;
struct Point
{
int a, b, c;
int time;
Point() { a = ; b = ; c = ; time = ; }
Point(int x, int y, int z, int step_time)
{
a = x; b = y; c = z; time = step_time;
}
}; int ans = ;
int A, B, C, game_times;
int map[MAX_N][MAX_N][MAX_N];
int move[][] =
{{, , -}, {, , }, {, -, }, {, , }, {-, , }, {, , }};
Point queue[]; int Bfs()
{
int head, tail;
Point temp; head = tail = ;
temp.a = temp.b = temp.c = temp.time = ;
queue[tail++] = temp; while (head != tail)
{
temp = queue[head++];
for (int i = ; i < ; ++i)
{
int next_a = temp.a + move[i][];
int next_b = temp.b + move[i][];
int next_c = temp.c + move[i][]; if (next_a < || next_b < || next_c <
|| next_a >= A || next_b >= B || next_c >= C
|| map[next_a][next_b][next_c] > || temp.time + > game_times)
continue; if (next_a == A - && next_b == B - && next_c == C - )
return temp.time + ; Point next(next_a, next_b, next_c, temp.time + );
map[next_a][next_b][next_c] = next.time;
queue[tail++] = next;
}
}
return -;
} int main()
{
int k; scanf("%d", &k);
while (k--)
{
scanf("%d %d %d %d", &A, &B, &C, &game_times);
for (int i = ; i < A; ++i)
for (int j = ; j < B; ++j)
for (int k = ; k < C; ++k)
scanf("%d", &map[i][j][k]); printf("%d\n", Bfs());
}
return ;
}
HDOJ 1253 胜利大逃亡(bfs)的更多相关文章
- hdoj 1253 胜利大逃亡
胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- hdu - 1240 Nightmare && hdu - 1253 胜利大逃亡(bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1240 开始没仔细看题,看懂了发现就是一个裸的bfs,注意坐标是三维的,然后每次可以扩展出6个方向. 第一维代表在 ...
- HDU 1253 胜利大逃亡(BFS)
题目链接 Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会.魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示成A ...
- Hdoj 1253.胜利大逃亡 题解
Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个ABC的立方体,可以被表示成A个B*C的矩 ...
- ny523 亡命逃串 hdoj 1253胜利大逃亡
亡命逃窜 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 从前有个叫hck的骑士,为了救我们美丽的公主,潜入魔王的老巢,够英雄吧.不过英雄不是这么好当的.这个可怜的娃被魔 ...
- hdoj 1429 胜利大逃亡(续) 【BFS+状态压缩】
题目:pid=1429">hdoj 1429 胜利大逃亡(续) 同样题目: 题意:中文的,自己看 分析:题目是求最少的逃亡时间.确定用BFS 这个题目的难点在于有几个锁对于几把钥匙.唯 ...
- hdu 1253:胜利大逃亡(基础广搜BFS)
胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- HDU 1253 胜利大逃亡 NYOJ 523【BFS】
胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- hdu 1253 胜利大逃亡 (三维简单bfs+剪枝)
胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
随机推荐
- Java基础知识总结(二)
&和&&的区别: 按位与:a&b是把a和b都转换成二进制数后逐位进行与的运算.若两数字的某位都为1,则该位的运算结果才为1.运算的最终结果是数字. 逻辑与:a& ...
- 本地搭建php环境
AppServ 是 PHP 网页架站工具组合包,所包含的软件有:Apache[.Apache Monitor.PHP.MySQL.phpMyAdmin等,如果您的本地机器没有安装过php.mysql等 ...
- CSS文本
CSS文字及文本 导航:1.文字及文本2.例子 1.文字及文本文字: 单个字符文本: 多个字符的组合体 2.例子2.1.文字的颜色颜色属性被用来设置文字的颜色格式: color:色值颜色是通过CSS最 ...
- ThinPHP第二十七天(kindEditor使用,$.each)
1.KindEditor简单使用实例 <js file="__PUBLIC__/kindeditor/kindeditor.js" /> <js file=&qu ...
- Python: how to public a model
1, Create a folder fileFolder 2, create a file tester.py 3, create another file setup.py: The conten ...
- lock table
1.在执行lock table语句后,则在执行unlock tables之前,当前会话只能操作当前被锁定的表(包括表别名)2.read锁,其它会话只有读取权限,没有写入权限3.write锁,其它会话只 ...
- QCombobox设置下拉框的宽度
这几天写一个项目,里面用到qcombobox组件,其中下拉框含有129个子项,所以在点击的时候,一个下拉框就将整个电脑屏幕给占满了,很不好看并且在使用中会造成很大的苦恼.其实我就是想设置一个下拉框最大 ...
- 升级automake和autoconf
<pre name="code" class="html">zjtest7-redis:/root/soft/json-c-json-c-0.12- ...
- linux date -d 的一些使用方法
date命令中格式输出类型字符含义例如以下: %% 一个文字的 % %a 当前locale 的星期名缩写(比如: 日,代表星期日) %A 当前locale 的星期名全称 (如:星期日) %b 当前lo ...
- poj1637Sightseeing tour(混合图欧拉回路)
题目请戳这里 题目大意:求混合图欧拉回路. 题目分析:最大流.竟然用网络流求混合图的欧拉回路,涨姿势了啊啊.. 其实仔细一想也是那么回事.欧拉回路是遍历所有边一次又回到起点的回路.双向图只要每个点度数 ...