BZOJ 4509 USACO 2016 Jan Gold Angry Cows

Bessie设计了一个游戏,将奶牛投掷到一个有多个草堆数轴上,奶牛的能量为R表示奶牛可以引爆半径R内的所有草堆,接着被引爆的这些草堆的能量为R-1,第二次被引爆的为R-2,以此类推,最后为0。问最小的R使得存在一个投掷点能引爆所有草堆。

发现,一个奶牛/草堆被引爆,其左右部分是不会影响的,可以考虑正反扫一次。
令dp1[i]表示i左边全部被引爆的最小半径,有:

dp1i=min{aiaj,dp1j+1+1}(aiaj>dp1j+1,j<i)

即表示最远直接引爆到j的最小半径。
然后发现dp1和j是单调递增的,因此 O(n)
dp2对称。
然后再枚举投掷点即可。
注意到投掷点只会在草堆上或草堆之间,因此投掷点的小数只有0和5两种情况,我们可以把所有坐标*2来解决小数的问题。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define rep(i,j,k) for(i=j;i<k;++i)
const int N = 50005;

int dp1[N], dp2[N], a[N];
int main() {
    int n, i, j, ans = 0x3f3f3f3f;
    scanf("%d", &n);
    rep(i,0,n) scanf("%d", a + i), a[i] *= 2;
    sort(a, a + n);
    n = unique(a, a + n) - a;
    memset(dp1, 127, sizeof dp1);
    dp1[j = 0] = -2;
    rep(i,1,n) {
        while (j + 1 < i && a[i] - a[j + 1] > dp1[j + 1] + 2)
            ++j;
        dp1[i] = min(a[i] - a[j], dp1[j + 1] + 2);
    }
    memset(dp2, 127, sizeof dp2);
    dp2[j = n - 1] = -2;
    for (i = n - 2; i >= 0; --i) {
        while (j - 1 > i && a[j - 1] - a[i] > dp2[j - 1] + 2)
            --j;
        dp2[i] = min(a[j] - a[i], dp2[j - 1] + 2);
    }
    for (i = 0, j = n - 1; i < j; ) {
        ans = min(ans, max((a[j] - a[i]) / 2, 2 + max(dp1[i], dp2[j])));
        if (dp1[i + 1] < dp2[j - 1]) ++i; else --j;
    }
    printf("%.1f", 1.0 * ans / 2);
    return 0;
}

4509: [Usaco2016 Jan]Angry Cows

Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 33 Solved: 13
[Submit][Status][Discuss]

Description

Bessie the cow has designed what she thinks will be the next big hit video game: “Angry Cows”. The premise, which she believes is completely original, is that the player shoots a cow with a slingshot into a one-dimensional scene consisting of a set of hay bales located at various points on a number line; the cow lands with sufficient force to detonate the hay bales in close proximity to her landing site, which in turn might set of a chain reaction that causes additional hay bales to explode. The goal is to use a single cow to start a chain reaction that detonates all the hay bales.
There are NN hay bales located at distinct integer positions x1,x2,…,xNx1,x2,…,xN on the number line. If a cow is launched with power RR landing at position xx, this will causes a blast of “radius RR”, engulfing all hay bales within the range x−R…x+Rx−R…x+R. These hay bales then themselves explode (all simultaneously), each with a blast radius of R−1R−1. Any not-yet-exploded bales caught in these blasts then all explode (all simultaneously) with blast radius R−2R−2, and so on.
Please determine the minimum amount of power RR with which a single cow may be launched so that, if it lands at an appropriate location, it will cause subsequent detonation of every single hay bale in the scene.

Input

The first line of input contains NN (2≤N≤50,000). The remaining NN lines all contain integers x1…xN (each in the range 0…1,000,000,000).

Output

Please output the minimum power RR with which a cow must be launched in order to detonate all the hay bales. Answers should be rounded and printed to exactly 1 decimal point.
Sample Input

5

8

10

3

11

1

Sample Output

3.0

In this example, a cow launched with power 3 at, say, location 5, will cause immediate detonation of hay bales at positions 3 and 8. These then explode (simultaneously) each with blast radius 2, engulfing bales at positions 1 and 10, which next explode (simultaneously) with blast radius 1, engulfing the final bale at position 11, which finally explodes with blast radius 0.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值