F - Aggressive cows

Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stalls are located along a straight line at positions x1,...,xN (0 <= xi <= 1,000,000,000).

His C (2 <= C <= N) cows don't like this barn layout and become aggressive towards each other once put into a stall. To prevent the cows from hurting each other, FJ want to assign the cows to the stalls, such that the minimum distance between any two of them is as large as possible. What is the largest minimum distance?

Input

* Line 1: Two space-separated integers: N and C

* Lines 2..N+1: Line i+1 contains an integer stall location, xi

Output

* Line 1: One integer: the largest minimum distance

Sample Input

5 3
1
2
8
4
9

Sample Output

3

Hint

OUTPUT DETAILS:

FJ can put his 3 cows in the stalls at positions 1, 4 and 8, resulting in a minimum distance of 3.

Huge input data,scanf is recommended.

  题目大意:题目会给出n个牛棚的坐标,要求将c头牛安置在这些牛棚中,使得每头的最小坐标间隔最大。
 #include<iostream>
#include<algorithm>
using namespace std; typedef long long ll;
int n,c;
ll a[]; int solve(ll x){
int cnt = ,drr=a[];
for(int i=; i<n; i++){
if(a[i] - drr >= x){
cnt++;
drr = a[i];
}
if(cnt >= c) return ;
}
return ;
}
int main(){
scanf("%d %d", &n, &c);
for(int i=; i<n; i++)
scanf("%d", a+i);
sort(a, a+n); ll left = ,right = ;
ll mid;
while(right - left > ){
mid = (left + right)/;
if(solve(mid)) left = mid;
else right = mid;
}
printf("%lld", left);
}

二分-F - Aggressive cows的更多相关文章

  1. POJ 2456 Aggressive cows(二分答案)

    Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22674 Accepted: 10636 Des ...

  2. bzoj1734 [Usaco2005 feb]Aggressive cows 愤怒的牛 二分答案

    [Usaco2005 feb]Aggressive cows 愤怒的牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 407  Solved: 325[S ...

  3. [ACM] poj 2456 Aggressive cows (二分查找)

    Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5436   Accepted: 2720 D ...

  4. BZOJ 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛( 二分答案 )

    最小最大...又是经典的二分答案做法.. -------------------------------------------------------------------------- #inc ...

  5. 疯牛-- Aggressive cows (二分)

    疯牛 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 农夫 John 建造了一座很长的畜栏,它包括N (2 <= N <= 100,000)个隔间,这些小 ...

  6. poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分

    poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分 题目链接: nyoj : http://acm.nyist.net/JudgeOnline/ ...

  7. 二分算法的应用——最大化最小值 POJ2456 Aggressive cows

    Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: Accepted: Description Far ...

  8. POJ - 2456 Aggressive cows 二分 最大化最小值

    Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18099   Accepted: 8619 ...

  9. POJ 2456 Aggressive cows (二分 基础)

    Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7924   Accepted: 3959 D ...

随机推荐

  1. 第四次oo博客作业

    (1)本单元是撰写UML数据分析器,架构大致如下,在指导书要求的函数外,对于UmlClass类,Umlinterface类,以及状态机,顺序图这四个类重现构造一个类,这个类里有他们所需要的全部信息,另 ...

  2. 【python基础语法】多重循环嵌套,函数(第6天课堂笔记)

    1.什么是函数?函数有什么作用? 函数都是有特定功能的,都是由一些有特定功能的进行封装完成的 2.已经学过了哪些内置函数?分别有什么作用? print:输出 input:输入 type:查询数据类型 ...

  3. git rm与git rm --cached的区别

    git rm与git rm --cached的区别 当我们需要删除暂存区或分支上的文件, 同时工作区也不需要这个文件了, 可以使用. git rm file_path git commit -m 'd ...

  4. PostgreSQL内核学习笔记十一(索引)

    Index Scan涉及到两部分的内容Heap Only Tuple和index-only-scan. 什么是Heap Only Tuple(HOT)? 例如:Update a Row Without ...

  5. 《茶余饭后小故事》MV*、MVC、MVP、MVVM的前世今生

    今天我们讲讲历史,讲讲故事,不扯高深术语. MV*表示的意思是:M(Model逻辑层) + View(视图层) + *(中间者).上帝提出了这个逻辑与视图分离,用中间者进行连接的伟大思想,并将实现这个 ...

  6. 【sklearn决策树算法】DecisionTreeClassifier(API)的使用以及决策树代码实例 - 鸢尾花分类

    决策树算法 决策树算法主要有ID3, C4.5, CART这三种. ID3算法从树的根节点开始,总是选择信息增益最大的特征,对此特征施加判断条件建立子节点,递归进行,直到信息增益很小或者没有特征时结束 ...

  7. BZOJ#2121. 字符串游戏 [区间dp]

    // powered by c++11 // by Isaunoya #include<bits/stdc++.h> #define rep(i , x , y) for(register ...

  8. Codeforces Round #592 (Div. 2) E

    给你一个数组,你最多可以进行k次操作,每次操作可以使一个数+1或者-1,问操作之后数组的极差最小可能是多少 利用map来模拟移动,可以观察到每次应该选择数量少的一组数让他们进行移动是最优的 int m ...

  9. R 拼接结果展示

    学长教的拼接结果展示 哇,R 简直太有魅力了! 晚一点补充

  10. beautifulsoup4进阶学习笔记

    requests库是可以找到想要的东西,基本上几行代码就搞定,但是进一步把有用的内容提取出来变成自己想要的格式来方便后续进行数据分析 正则表达式提取的话,需要一些时间成本,这个可以每天积累一点. 这里 ...