题目链接:

https://vjudge.net/problem/POJ-2456

题目大意:

有n个牛栏,选m个放进牛,相当于一条线段上有 n 个点,选取 m 个点, 使得相邻点之间的最小距离值最大

解题思路:

二分枚举最小距离的最大值

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int INF = 1e9;
const int maxn = ;
int n, m;
int a[maxn];
bool judge(int x)
{
int last = ;
for(int i = ; i < m; i++)
{
int now = last + ;
while(now <= n && a[now] - a[last] < x)now++;
last = now;
}
return last <= n;
}
int main()
{
cin >> n >> m;
for(int i = ; i <= n; i++)cin >> a[i];
sort(a + , a + n + );
int l = , r = INF + , ans;
while(l <= r)
{
int mid = (l + r) / ;
if(judge(mid))
ans = mid, l = mid + ;
else r = mid - ;
}
cout<<ans<<endl;
return ;
}

POJ-2456 Aggressive cows---最大化最小值(也就是求最大值)的更多相关文章

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

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

  2. 二分搜索 POJ 2456 Aggressive cows

    题目传送门 /* 二分搜索:搜索安排最近牛的距离不小于d */ #include <cstdio> #include <algorithm> #include <cmat ...

  3. POJ 2456 Aggressive cows ( 二分搜索)

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

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

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

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

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

  6. POJ 2456 Aggressive cows (二分)

    题目传送门 POJ 2456 Description Farmer John has built a new long barn, with N (2 <= N <= 100,000) s ...

  7. POJ 2456 Aggressive cows

    Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11192   Accepted: 5492 ...

  8. [POJ] 2456 Aggressive cows (二分查找)

    题目地址:http://poj.org/problem?id=2456 最大化最小值问题.二分牛之间的间距,然后验证. #include<cstdio> #include<iostr ...

  9. POJ 2456 Aggressive cows(贪心 + 二分)

    原题链接:Aggressive cows 题目大意:农夫 建造了一座很长的畜栏,它包括  个隔间,这些小隔间依次编号为. 但是, 的  头牛们并不喜欢这种布局,而且几头牛放在一个隔间里,他们就要发生争 ...

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

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

随机推荐

  1. linux 远程装机

    首先,服务器配置dhcp  关闭火墙yum install dhcp -ycd   /etc/dhcpcp   /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example ...

  2. PHP任意文件上传漏洞(CVE-2015-2348)

    安全研究人员今天发布了一个中危漏洞——PHP任意文件上传漏洞(CVE-2015-2348). 在上传文件的时候只判断文件名是合法的文件名就断定这个文件不是恶意文件,这确实会导致其他安全问题.并且在这种 ...

  3. mybatis用法

    转载:https://www.cnblogs.com/xdp-gacl/p/4261895.html 一.Mybatis介绍 MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架 ...

  4. eclipse安装阿里规范模板

    https://github.com/alibaba/p3c/tree/master/p3c-formatter 1.代码模板(含注释等) 2.代码格式化

  5. Webstrom 中写Vue没有代码提示如何解决?

    1. 如果你的Webstorm是2017版的,请更新到最新的2018,2018版本的webstorm自带了vue插件 找到 Help > About,查看你的Webstorm版本 2. 如果你的 ...

  6. 在ubuntu中安装mysql及简单操作方式

    老规矩,ctrl+alt+t呼出终端, 输入 sudo apt-get update 更新源,否则在运行下面代码时会报出有几个包无法下载,你还是得回来执行这句代码, 输入 sudo apt-get i ...

  7. java多线程(四)

    一个例子: Account.java 客户实体类 package com.asiainfo.test.thread8; /** * 账户类 * @author luke * */ public cla ...

  8. TCP/IP协议<一>

    下面是协议层从底层至顶层的一个模型图: 一.计算机网络的背景 1.1 计算机的发展 有人说:“20世纪最伟大的发明就是计算机”,自诞生伊始,计算机经历了一系列发展,从大型通用计算机.超级计算机.小型机 ...

  9. Android NDK开发 图片处理(五)

    做过Java的同学可能经常会遇到一些关于图片处理的 例如类似QQ离线头像显示灰的.最快的算法是用colorMatrix来实现.这里通过Java调用JNI来处理每一个像素来实现. 对每一个像素点取出RG ...

  10. RTT之ENV

    一 先安装工具git:在CMD命令行中运行git命令检验git环境变量安装成功 二 下载env工具:然后解压,打开对应的exe然后右击-setting-intergration-registor这样后 ...