bzoj4525: [Usaco2016 Jan]Angry Cows

二分。

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 50000 + 10;

int n,k,l,r,mid,ans,d;
int a[maxn];

bool check(int dist) {
    dist=2*dist;
    int d=0,sum=1;
    for(int i=2;i<=n;i++) {
        if(a[i]-a[i-1]>dist-d) {
            sum++;
            d=0;
        }
        else d+=a[i]-a[i-1];
    }
    //printf("%d %d\n",dist/2,sum);
    return sum<=k;
}

int main() {
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    l=1;r=a[n];
    while(l<r) {
        mid=(l+r)>>1;
        if(check(mid)) r=mid;
        else l=mid+1;
    }
    printf("%d\n",l);
    return 0;
}
时间: 2024-10-06 22:08:37

bzoj4525: [Usaco2016 Jan]Angry Cows的相关文章

bzoj4509【Usaco2016 Jan】Angry Cows

4509: [Usaco2016 Jan]Angry Cows Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 83  Solved: 38 [Submit][Status][Discuss] Description Bessie the cow has designed what she thinks will be the next big hit video game: "Angry Cows". The premise, whi

bzoj 4506: [Usaco2016 Jan]Fort Moo

4506: [Usaco2016 Jan]Fort Moo Description Bessie is building a fort with her friend Elsie. Like any good fort, this one needs to start with a sturdy frame. Bessie wants to build a frame in the shape of a one-meter-wide rectangular outline, atop which

bzoj4510: [Usaco2016 Jan]Radio Contact

bzoj4510: [Usaco2016 Jan]Radio Contact Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 21  Solved: 17[Submit][Status][Discuss] Description Farmer John has lost his favorite cow bell, and Bessie the cow has agreed to help him find it! They both fan ou

bzoj4511: [Usaco2016 Jan]Subsequences Summing to Sevens

前缀和. 设f[i]为前缀和%7=i的第一个点.那么答案就是max(i-f[s[i]%7])了. #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int maxn = 50000 + 10; int a[maxn],s[maxn]; int f[10],n,ans; int main() { for(int i=1;i<7;i++) f[i]=-1;

bzoj4512: [Usaco2016 Jan] Build Gates

题目大意:给个序列,求最长的连续子序列使其为7的倍数 又是一道令人欢喜的不用怎么用脑的水题.. 边读入,边计算前缀和 分别保存前缀和%7结果为1,2,3,4,5,6的第一次的位置 然后减一减就知道长度啦. 1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 using namespace std; 5 int n,t,last[8],ans; 6 long long sum[50010]; 7

BZOJ4509 Angry Cows(dp)

题意: 大概就是一条线上有n个炸弹,然后让你随意扔一个爆炸半径为r的炸弹使他们全部爆炸, 第一次被引爆的炸弹爆炸半径为r-1,第二次为r-2... 求r最小是多少 思路: 用两个数组处理得到从左往右和从右往左到当前炸弹时的爆炸半径最小是多少,然后枚举投弹位置就可以了 /* *********************************************** Author :devil ************************************************ */

[BZOJ4506] [Usaco2016 Jan]Fort Moo(DP?)

传送门 总之可以先预处理出来每个位置最多往上延伸多少 枚举两行,看看夹在这两行中间的列最大能构成多大的矩形 可以看出,必须得在一个两行都没有X的区间才有可能构成最大的答案 那么可以把这些区间处理出来,在看看这些区间中的点最左边和最右边的能从下面那一行向上延伸到上面那一行的点,更新ans即可 #include <cstdio> #define N 201 #define max(x, y) ((x) > (y) ? (x) : (y)) int n, m, ans, p; int h[N]

[USACO16JAN]愤怒的奶牛Angry Cows

传送门 一道神奇的DP---(鬼知道他为什么在tarjan里面) 一开始可能会考虑贪心或者什么其他神奇的算法,不过还是DP比较靠谱. 我们用f[i]表示摧毁所有i左侧的炸 药包最少需要的能量,用g[i]表示摧毁所有i右侧的炸 药包最少需要的能量. 那么我们只要找到满足j < i,a[i] - a[j] > f[j]+1的最后一个j炸 药包,就可以更新f[i]的值,f[i]  = min(f[i],a[i]-a[j],f[j]+1); 同样的g也是同理. 为什么这么找呢--因为首先我们发现如果a

usaco16 jan gold

T1:angry cows 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 co