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. PVE裸机虚拟化环境安装之后的一些部署记录

    pve镜像使用的是proxmox-ve_6.1-1 安装之后root登录 apt update 更新源的时候会出现一些问题,是因为其中有一个企业源报错的原因 安装sudo和vim,否则不好管理非roo ...

  2. MySql学习-5.查询2

    1.聚合: 1.1 5个聚合函数: count(*):括号中写列名,或者 *: max(列):此列的最大值: min(列):此列的最小值: sum(列):此列的和: avg(列):此列的平均值: 1. ...

  3. WPF 控件功能重写(ComboBox回车搜索)

    前言:在我们日常使用软件的时候,Combobox会让用户很方便的选择出需要的东西,但是ComboBox中的下拉行数过多时就不那么好用了. 如果在项目中有很多这样的ComboBox控件的话,我们可以考虑 ...

  4. W25Q64BV(FLASH)(SPI)中文手册

    64兆位串行SPI FLASH存储器 1.常规介绍 W25Q64BV(64兆位)串行FLASH存储器为一个空间大小,引脚,功耗限制的系统提供解决方案.25Q系列的灵活性和性能良好超越了普通的串行FLA ...

  5. disabled属性对form表单提交的影响

    在form表单里,如果对input加入disabled="disabled"或disabled="true"等属性,form表单提交的时候,就不会传值到后台. ...

  6. ThinkPHP v6.0.x 反序列化漏洞利用

    前言: 上次做了成信大的安询杯第二届CTF比赛,遇到一个tp6的题,给了源码,目的是让通过pop链审计出反序列化漏洞. 这里总结一下tp6的反序列化漏洞的利用. 0x01环境搭建 现在tp新版本的官网 ...

  7. windows 2012 r2怎么进入本地组策略

    可以使用命令行或使用 Microsoft 管理控制台 (MMC) 打开本地组策略编辑器.通过命令行打开本地组策略编辑器的步骤单击“开始”,在“开始搜索”框中键入 gpedit.msc,然后按 Ente ...

  8. 【Spring】事务(transactional)之初步理解

    一. 场景 有一个定时器,做数据库表数据同步. 把数据库A的表table(DB_A_TABLE)同步到数据库B的表table(DB_B_TABLE). 对于DB_A_TABLE的每行数据要做一定的逻辑 ...

  9. 文件流之输入输出(类似于freopen重定向)

    利用标准文件操作函数进行数据的输入输出,所用函数均在stdio.h中,类似于freopen重定向文件. 该方法的思路是: (1)建立文件指针 (2)打开文件,将文件指针指向打开的文件,并决定打开的文件 ...

  10. UVA1395 (最苗条的最小生成树)

    链接 https://vjudge.net/problem/UVA-1395 代码 #include<bits/stdc++.h> using namespace std; #define ...