1、题意:给一堆可以的限制长度的区间。。。区间的长度是你控制的。。。但是只有一个长度。。。求最短长度覆盖所有的点

2、分析:发现可以二分。。。那二分吧。。。。。然后我们从头向后扫一遍直接判断能否直接覆盖。。。然后就可以AC了《大赛后一水系列》

#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define LL long long
#define inf 2147483647
#define M 100010

inline int read(){
    char ch = getchar(); int x = 0, f = 1;
    while(ch < '0' || ch > '9'){
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while('0' <= ch && ch <= '9'){
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
} 

int a[M];
int n, K;

inline bool check(int x){
    int l = 1, o = 0;
    for(int i = 1; i <= n; i ++){
        if(a[i] - a[l] > x * 2){
            o ++;
            l = i;
        }
    }
    o ++;
    return o <= K;
}

int main(){
    n = read(), K = read();
    for(int i = 1; i <= n; i ++) a[i] = read();
    sort(a + 1, a + n + 1);
    int l = 0, r = 1000000000, t = 1000000000;
    while(l <= r){
        int mid = (l + r) / 2;
        if(check(mid)) r = (t = mid) - 1;
        else l = mid + 1;
    }
    printf("%d\n", t);
    return 0;
}

BZOJ4525——[Usaco2016 Jan]Angry Cows的更多相关文章

  1. bzoj4525: [Usaco2016 Jan]Angry Cows

    二分. #include<cstdio> #include<algorithm> #include<cstring> using namespace std; + ...

  2. NC24017 [USACO 2016 Jan S]Angry Cows

    NC24017 [USACO 2016 Jan S]Angry Cows 题目 题目描述 Bessie the cow has designed what she thinks will be the ...

  3. USACO2016 January Gold Angry Cows

    Angry Cows 题目描述:给出数轴上的\(n\)个整点\((a[i])\),现在要在数轴上选一个位置\(x\)(可以是实数),以及一个半径\(R\),在以\(x\)为中心,半径为\(R\)的范围 ...

  4. bzoj 4506: [Usaco2016 Jan]Fort Moo

    4506: [Usaco2016 Jan]Fort Moo Description Bessie is building a fort with her friend Elsie. Like any ...

  5. bzoj4506: [Usaco2016 Jan]Fort Moo(暴力)

    4506: [Usaco2016 Jan]Fort Moo Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 145  Solved: 104[Submi ...

  6. bzoj4512[Usaco2016 Jan] Build Gates

    bzoj4512[Usaco2016 Jan] Build Gates 题意: 某人从农场的(0,0)出发,沿边界到处乱走,走过的地方会留下栅栏,等走完后问要在多少个栅栏上开门才能使整个农场连通,最多 ...

  7. bzoj4511:[Usaco2016 Jan]Subsequences Summing to Sevens

    题目大意:给个序列,求最长的连续子序列使其为7的倍数 又是一道令人欢喜的不用怎么用脑的水题.. 边读入,边计算前缀和 分别保存前缀和%7结果为1,2,3,4,5,6的第一次的位置 然后减一减就知道长度 ...

  8. bzoj4511: [Usaco2016 Jan]Subsequences Summing to Sevens

    前缀和. 设f[i]为前缀和%7=i的第一个点.那么答案就是max(i-f[s[i]%7])了. #include<cstdio> #include<algorithm> #i ...

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

    传送门 总之可以先预处理出来每个位置最多往上延伸多少 枚举两行,看看夹在这两行中间的列最大能构成多大的矩形 可以看出,必须得在一个两行都没有X的区间才有可能构成最大的答案 那么可以把这些区间处理出来, ...

随机推荐

  1. su su- sudo的区别

    linux su命令参数及用法详解(linux切换用户命令) su的作用是变更为其它使用者的身份,超级用户除外,需要键入该使用者的密码   linux su 命令 建议大家切换用户的时候 使用 su ...

  2. Mysql数据库设置定时任务

    最近手头在做一个拍卖的电商项目. 中间需要将到点的拍卖会状态设置为进行中. 我们的解决方案是Mysql的定时器任务,这里进行一个简单的总结. 1.使用范围 不是所有的MySQL版本都支持,Mysql ...

  3. linq 之 Distinct的使用

    public class Product { public string Name { get;set;} public int Code { get; set; } } class ProductC ...

  4. easyUI文本框textbox笔记

    知识点: 1.图标位置 Icon Align属性,有left和right两个: 2.textbox的setvalue方法,getvalue方法. <div style="margin: ...

  5. expect神器安装和使用

    安装: mdkir /data/tools cd /data/tools wget http://prdownloads.sourceforge.net/tcl/tcl8.5.19-src.tar.g ...

  6. Python + OpenCV2 系列:3 - python 字符串,类,编码规范

    首先,强烈推荐<<简明 Python 教程>> Swaroop, C. H. 著 沈洁元 译 其实,这本书里已经把python的最基本的用法,编码等等介绍的很好,这里把我用到的 ...

  7. OpenGL Tutorial

    https://open.gl https://www.processing.org/tutorials/pshader/

  8. webapi输入验证过滤器ValidationActionFilter

    public class validationActionFilter:ActionFilterAttribute { public override void OnActionExecuting(S ...

  9. ASP.NET WebForm中用async/await实现异步

    1. 在.aspx中添加异步标记 <%@ Page Language="C#" Async="true"%> 2. 在.aspx.cs或者.ascx ...

  10. Java读取txt文件,计算2011年9月份的通话时间

    public class test2 { /** * @param args * @throws IOException */ public static void main(String[] arg ...