HDU 3533 Escape(大逃亡)

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768K (Java/Others)

 

Problem Description - 题目描述

  The students of the HEU are maneuvering for their military training.
  The red army and the blue army are at war today. The blue army finds that Little A is the spy of the red army, so Little A has to escape from the headquarters of the blue army to that of the red army.
  The battle field is a rectangle of size m*n, and the headquarters of the blue army and the red army are placed at (0, 0) and (m, n), respectively, which means that Little A will go from (0, 0) to (m, n). The picture below denotes the shape of the battle field and the notation of directions that we will use later.
HEU的同学正在进行军事训练。
红队和蓝队正在交战。蓝队发现小A是红队的间谍,因此小A必须逃出蓝队总部前往红队总部。
战场是块m*n的矩形,并且蓝队和红队的总部分别在(, ) 和(m, n),意味着小A要从(, ) 到 (m, n)。下图是战场与方向的示意图。

CN

  The blue army is eager to revenge, so it tries its best to kill Little A during his escape. The blue army places many castles, which will shoot to a fixed direction periodically. It costs Little A one unit of energy per second, whether he moves or not. If he uses up all his energy or gets shot at sometime, then he fails. Little A can move north, south, east or west, one unit per second. Note he may stay at times in order not to be shot.
  To simplify the problem, let’s assume that Little A cannot stop in the middle of a second. He will neither get shot nor block the bullet during his move, which means that a bullet can only kill Little A at positions with integer coordinates. Consider the example below.
  The bullet moves from (0, 3) to (0, 0) at the speed of 3 units per second, and Little A moves from (0, 0) to (0, 1) at the speed of 1 unit per second. Then Little A is not killed. But if the bullet moves 2 units per second in the above example, Little A will be killed at (0, 1).
  Now, please tell Little A whether he can escape.

蓝队亟欲报复,所以打算对逃跑的小A进行拦截。蓝队安置了许多城堡,城堡会朝一个固定方向定时射击。小A每分钟消耗1点能量,无论是否移动。如果他能量耗尽或者中弹,就跪了。小A每分钟可朝东南西北方向移动一个单位。注意,他有时会为了规避射击而选择滞留。
为了简化问题,我们假设小A不会停在半路上。并且他在移动的时候不会中弹或挡住子弹,这表示子弹只能整数坐标上击杀小A。例子如下。
子弹以每秒3个单位的速度从 (, ) 到(, ),小A以每秒1个单位的速度从(, ) 到(, )。小A犹存。然而如果上面的子弹速度为每秒2个单位,在(, )小A卒。

CN

Input - 输入

  For every test case, the first line has four integers, m, n, k and d (2<=m, n<=100, 0<=k<=100, m+ n<=d<=1000). m and n are the size of the battle ground, k is the number of castles and d is the units of energy Little A initially has.
  The next k lines describe the castles each. Each line contains a character c and four integers, t, v, x and y. Here c is ‘N’, ‘S’, ‘E’ or ‘W’ giving the direction to which the castle shoots, t is the period, v is the velocity of the bullets shot (i.e. units passed per second), and (x, y) is the location of the castle.
  Here we suppose that if a castle is shot by other castles, it will block others’ shots but will NOT be destroyed. And two bullets will pass each other without affecting their directions and velocities.
  All castles begin to shoot when Little A starts to escape.
  Proceed to the end of file.

对于每个测试用例,第一行为四个整数,m,n,k,和d(<=m, n<=, <=k<=, m+ n<=d<=)。m和n表示战场大小,k是城堡的数量,d是小A的初始能量。
随后k行城堡描述。每行有一个字符c和四个整数t,v,x,y。c为‘N’, ‘S’, ‘E’ 或‘W’表示城堡的射击方向,t为周期,v表示子弹的速度(每分钟通过的单位数),还有(x, y)表示城堡的位置。
这里我们假设如果一个城堡被其他城堡射击,它能挡下设计却不会被破坏。两个子弹可以相互穿过且不影响速度与方向。
小A开始跑路的同时,城堡也开始射击。
输入持续到文件结束。

CN

Output - 输出

  If Little A can escape, print the minimum time required in seconds on a single line. Otherwise print “Bad luck!” without quotes.

如果小A可以逃脱,输出一行所需的最短时间,单位为秒。否则输出“Bad luck!” ,没有引号。

CN

Sample Input - 输入样例

4 4 3 10
N 1 1 1 1
W 1 1 3 2
W 2 1 2 4
4 4 3 10
N 1 1 1 1
W 1 1 3 2
W 1 1 2 4

Sample Output - 输出样例

9
Bad luck!

题解

  条件多一点的BFS,顺便有点坑爹。
  题目的x,y需要互换,最坑爹的是敌人的城堡不能碰……(百思不得其解地惨烈WA了许久之后偶然尝试出来的)

代码 C++

 #include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#define INF 0x7F7F7F7F
#define MX 105
int map[MX][MX], fx[] = { -, , , , , -, , }, mp[];
bool ban[MX][MX][MX];
struct Point {
int y, x;
}now, nxt;
std::queue<Point> q;
int pc[MX], pt[MX], pv[MX], px[MX], py[MX];
int main() {
int m, n, k, d, c, t, v, x, y;
int i, j;
char tmp;
mp['N'] = ; mp['S'] = ; mp['W'] = ; mp['E'] = ;
while (~scanf("%d%d%d%d ", &m, &n, &k, &d)) {
memset(map, INF, sizeof map); memset(ban, , sizeof ban);
for (i = ; i < k; ++i) {
scanf("%c%d%d%d%d ", &tmp, pt + i, pv + i, py + i, px + i);
pc[i] = mp[tmp];
--map[py[i]][px[i]];
}
for (i = ; i < k; ++i) {
c = pc[i]; t = pt[i]; v = pv[i]; y = py[i]; x = px[i];
for (j = v, t = ; j == v; ++t) {
for (j = t; j < MX; j += pt[i]) ban[y][x][j] = ;
for (j = ; j < v; ++j) {
y += fx[c]; x += fx[c + ];
if (y< || y>m || x< || x>n) break;
if (map[y][x] != INF) break;
}
}
} map[][] = ;
now.y = now.x = ; q.push(now);
while (!q.empty()) {
now = q.front(); q.pop();
t = map[now.y][now.x] + ;
if (t > d) continue;
for (i = ; i < ; i += ) {
y = now.y + fx[i]; x = now.x + fx[i + ];
if (y< || y>m || x< || x>n) continue;
if (t >= map[y][x]) continue;
if (map[y][x] == INF - ) continue;
if (ban[y][x][t]) continue;
map[y][x] = t; nxt.y = y; nxt.x = x;
if (y != m || x != n) q.push(nxt);
}
if (ban[y][x][t]) {
++map[now.y][now.x]; q.push(now);
}
}
if (map[m][n] > d) puts("Bad luck!");
else printf("%d\n", map[m][n]);
}
return ;
}

HDU 3533 Escape(大逃亡)的更多相关文章

  1. hdu 1429 胜利大逃亡(续)

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王 ...

  2. HDU 1429 胜利大逃亡(续)(bfs+状态压缩,很经典)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)  ...

  3. hdu.1429.胜利大逃亡(续)(bfs + 0101011110)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  4. 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 ...

  5. hdu 1429 胜利大逃亡(续)(bfs+位压缩)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  6. HDU 1429 胜利大逃亡(续)(DP + 状态压缩)

    胜利大逃亡(续) Problem Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)…… 这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢 ...

  7. hdu 1253 胜利大逃亡 (三维简单bfs+剪枝)

    胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  8. [ACM] hdu 1253 胜利大逃亡 (三维BFS)

    胜利大逃亡 Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这但是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个A*B*C的立方体,能够被表示 ...

  9. hdu 1253 胜利大逃亡 (代码详解)解题报告

    胜利大逃亡 Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示 ...

随机推荐

  1. python 去掉重复元素 学到再添加

    1. python 内置函数 set(可迭代对象) 返回无重复元素的集合.如在分类中,classification为类别数组 set(classification)为类别数 2.numpy np.un ...

  2. 常用Java技术社区

      Java生态圈知识链: 求职平台 阿里巴巴社招平台 杭州网易社招平台 微店社招平台 银联社招平台 百度社招平台 Java生态圈知识链: 个人优秀博客 腾讯_运维工程师_刘天斯 阿里_Android ...

  3. ROS学习备忘

    1. remap的解释 For example, you are given a node that says it subscribes to the "chatter" top ...

  4. E. Neko and Flashback

    传送门: 题意:假定我们已知a[]={3,4,6,5,7},  那么b[]通过min(a[i],a[i+1])得到 那么b[]={3,4,5,5}, c[]通过max(a[i],a[i+1])得到 c ...

  5. 个人对stm32ADC编程关键点的理解

    平时在做项目或者参加比赛的过程中,个人觉得,有些东西写出来可能会帮助到新手少走弯路.(也很可能是错误的,欢迎大家纠错) 如果只是采集一路信号,直接用ADC独立模式,单通道就可以了. 如果需要同时采集多 ...

  6. JavaScript 区分中英文字符的两种方法: 正则和charCodeAt()方法

    正则无疑是最强大的判断各种条件的方法, 最近也在研习它, 虽然枯燥, 但仍有乐趣. 用它来判断一个双字节的中文字符也是轻而易举地. 而判断中文字符,  简单且执行效率高. regExpForm.onb ...

  7. 003-单例OR工厂模式

    单例模式:DbContextFactory.cs using CZBK.ItcastOA.Model; using System; using System.Collections.Generic; ...

  8. PHP filter_var 函数用法

    先介绍下PHP Filter PHP手册地址:http://php.net/manual/zh/ref.filter.php PHP 过滤器用于对来自非安全来源的数据(比如用户输入)进行验证和过滤. ...

  9. XML文件的读取

    <?xml version="1.0" encoding="gbk"?> <!--设置编码格式为gbk--> <!DOCTYPE ...

  10. Python生成器的原理及使用

    '''1,什么是生成器? 函数内但凡有一个yield关键字, 再调用函数就不会执行函数代码,得到的返回值就是一个生成器对象 生成器本身就是一种迭代器 next(g)过程: 会触发生成器g所对应的函数的 ...