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 ...
随机推荐
- hibernate sql查询后对象转换成实体类
在多表查询的时候使用hibernate的sql查询的时候,一般返回的是object[]数组,或者可以使用 session.createSQLQuery(sql).setResultTransform ...
- BZOJ 2302: [HAOI2011]Problem c( dp )
dp(i, j)表示从i~N中为j个人选定的方案数, 状态转移就考虑选多少人为i编号, 然后从i+1的方案数算过来就可以了. 时间复杂度O(TN^2) ------------------------ ...
- Hive入门之UDFS函数
一.UDFS函数介绍 1. 基本UDF (1)SHOWFUNCTIONS:这个用来熟悉未知函数. DESCRIBE FUNCTION<function_name>; (2)A IS NUL ...
- SQL Server 查看数据表占用空间大小的SQL语句
) ) if object_id('tempdb..#space') is not null drop table #space ),rows ),data ),index_size ),unused ...
- codeforces 463C Gargari and Bishops
题目链接 这个题, 最主要的应该是找到对角线上的格子的关系. “ \" 这种对角线, 关系是x-y+n相等, ” / “ 这种, 关系是x+y相等.知道每个格子的两种对角线的值, 那么这个格 ...
- [C++]Standing Ovation——Google Code Jam 2015 Qualification Round
Problem It’s opening night at the opera, and your friend is the prima donna (the lead female singer) ...
- shell实现死循环
参考自http://codingstandards.iteye.com/blog/780524 .while true do command; done .while : do command; do ...
- Linux菜鸟之路[4]-cal,date,bc,echo $LANG,man
由于前四天一直在看鸟哥的linux书本的计算机的一些基础知识,今天才接触基本的命令,从今天起每天记录一下自己的linux学习过程. cal:日历 cal: cal 2015:列出2015年所有日历 c ...
- android小知识之意图(intent)
android中的意图有显示意图和隐式意图两种, 显示意图要求必须知道被激活组件的包和class 隐式意图只需要知道跳转activity的动作和数据,就可以激活对应的组件 A 主activity B ...
- 三种尺寸:手机SIM卡使用指南
毫无疑问目前卖的最火的手机非iPhone 5s莫属,相信仍有不少网友目前处于观望之中,由于iPhone 5s和iPhone 5c采用与iPhone相同的Nano-SIM卡,因此不少新用户在使用之前也徒 ...