1734: [Usaco2005 feb]Aggressive cows 愤怒的牛

Description

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?

农夫 John 建造了一座很长的畜栏,它包括NN (2 <= N <= 100,000)个隔间,这些小隔间依次编号为x1,...,xN (0 <= xi <= 1,000,000,000). 但是,John的C (2 <= C <= N)头牛们并不喜欢这种布局,而且几头牛放在一个隔间里,他们就要发生争斗。为了不让牛互相伤害。John决定自己给牛分配隔间,使任意两头牛之间的最小距离尽可能的大,那么,这个最大的最小距离是什么呢

Input

* Line 1: Two space-separated integers: N and C * Lines 2..N+1: Line i+1 contains an integer stall location, xi

第一行:空格分隔的两个整数N和C

第二行---第N+1行:i+1行指出了xi的位置

Output

* Line 1: One integer: the largest minimum distance

第一行:一个整数,最大的最小值

Sample Input

5 3
1
2
8
4
9

Sample Output

3
把牛放在1,4,8这样最小距离是3
题解:
很明显的二分答案。。
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=;
int n,m,i,a[N];
int erfen(int l,int r)
{
if(l>r) return r;
int mid=(l+r)>>,x=a[],k=;
for(i=;i<=n;i++)
if(a[i]-x>=mid)
{
x=a[i];
k++;
}
if(k>=m) return erfen(mid+,r);else return erfen(l,mid-);
}
int main()
{
scanf("%d%d",&n,&m);
for(i=;i<=n;i++)
scanf("%d",&a[i]);
sort(a+,a+n+);
cout<<erfen(,a[n]-a[]);
return ;
}
 

bzoj 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛的更多相关文章

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

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

  2. bzoj 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛【二分+贪心】

    二分答案,贪心判定 #include<iostream> #include<cstdio> #include<algorithm> using namespace ...

  3. 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛

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

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

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

  5. bzoj1734 [Usaco2005 feb]Aggressive cows 愤怒的牛

    Description Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stal ...

  6. B1734 [Usaco2005 feb]Aggressive cows 愤怒的牛 二分答案

    水题,20分钟AC,最大值最小,一看就是二分答案... 代码: Description Farmer John has built a <= N <= ,) stalls. The sta ...

  7. BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛( floyd + 二分答案 + 最大流 )

    一道水题WA了这么多次真是.... 统考终于完 ( 挂 ) 了...可以好好写题了... 先floyd跑出各个点的最短路 , 然后二分答案 m , 再建图. 每个 farm 拆成一个 cow 点和一个 ...

  8. [BZOJ 1733] [Usaco2005 feb] Secret Milking Machine 【二分 + 最大流】

    题目链接:BZOJ - 1733 题目分析 直接二分这个最大边的边权,然后用最大流判断是否可以有 T 的流量. 代码 #include <iostream> #include <cs ...

  9. bzoj:1675 [Usaco2005 Feb]Rigging the Bovine Election 竞选划区

    Description It's election time. The farm is partitioned into a 5x5 grid of cow locations, each of wh ...

随机推荐

  1. aptitude约等于apt-get的工具

    如题,与之不同的是其会将依赖的程序也给删除. https://baike.baidu.com/item/aptitude/6849487?fr=aladdin 以下是一些常用 aptitude命令,仅 ...

  2. DirectX介绍(转)

    原文转自 https://baike.baidu.com/item/Direct3D/910353

  3. libSVM笔记之(一)在matlab环境下安装配置libSVM

    本文为原创作品,转载请注明出处 欢迎关注我的博客:http://blog.csdn.net/hit2015spring和http://www.cnblogs.com/xujianqing 台湾林智仁教 ...

  4. 蓝屏代码0X0000007B可能是SATA mode问题

    Win7蓝屏代码0X0000007B可能是硬盘模式的问题,我进入BIOS把SATA的mode从Enhanced改为Compatible(及IDE兼容模式)结果系统可以顺利启动没有问题.       从 ...

  5. EF添加ADO.NET实体模型处直接选择Oracle数据源

    上一文介绍了如何下载Mysql for vs Tools来进行Mysql的ADO.NET实体模型数据源选择,今天将Oracle的测试了下.步骤如下: 1.在你项目Model层中nuget安装选中项 2 ...

  6. Sql Server 2014/2012/2008/2005 数据库还原出现 3154错误的解决办法

    在Sql Server  数据库还原出现 3154错误 解决方法1:不要在数据库名字上点右键选择还原,而要是在根目录“数据库”三个字上点右键选择还原,然后再选择数据库,问题便可以解决,如果不行参照方法 ...

  7. [New learn]AutoLayout调查基于code

    代码https://github.com/xufeng79x/TestAutolayout-code2 0.插在前面 必须关闭view的自动缩放掩码,自动缩放掩码是autolayout出现之前系统管理 ...

  8. FineReport——权限分配以及自定义首页

    权限分配可以有两种方法,第一种方法是根据部门职位分配权限,第二种是根据角色分配权限: FR自带有三个JQ对象,用以保存用户名参数/角色参数/部门参数——$fr_username/$fr_authori ...

  9. 关于指针pointer的位数与程序有关还是与系统有关、以及指针的指针的理解

  10. Freemarker中JS取Data-model的值的问题

    不能在表达式中使用js变量,比如: var key = 1; var value = "${stateMap[key]}"; 因为Freemarker是在服务器端进行解析的,此时j ...