题目链接:

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. slf4j与log4j、log4j2

    https://blog.csdn.net/yangzl2008/article/details/81503579 https://blog.csdn.net/HarderXin/article/de ...

  2. my14_mysql指定时间恢复之模拟从库

    场景 *********************************线上库数据误删除,存在几天前的一份全备数据,现需要恢复这些误删除的数据本例方案:在另外一台服务器上,恢复全备,搭建binlog ...

  3. ubuntu replace system openjdk

    一些ubuntu自带jdk的.但是有时候会确实我们所要的文件.下面介绍如何replace jdk 1. 卸载现有jdk sudo apt-get purge openjdk-\* 2. 下载jdk. ...

  4. ora-1652

    ###检查是否有temp 在使用 step 2: 检查是否有事务使用到temp,并且进行删除. SELECT vt.inst_id,vs.sid,vs.serial#,vs.username,vs.o ...

  5. 那些NPM文档中我看不懂地方

    $cookies.set(keyName, value[, expireTimes[, path[, domain[, secure]]]]) //return this 中括号代表可选参数 上面一行 ...

  6. 使用Myeclipse导入IDEA项目

    问题描述:使用Myeclipse导入IDEA创建的Web项目,成功导入,但是显示的是一个普通的JAVA项目,无法加载到tomcat下. 解决方案:右键项目Properties,选择Myeclipse- ...

  7. DEDE文章列表加上序号效果

    在文章列表上面加上序号列表的形式,使得文章列表表现得没那么单调,更加丰富一点. {dede:arclist orderby=pubdate type='commend.' titlelen='26' ...

  8. 几个CSS的黑科技

    这里的黑科技其实就是一些CSS中不怎么为人所知但在解决某些问题的时候很溜的属性. border-radius 很多开发者估计都没有正确认识这个border-radius,因为基本上很多人都是这么用的: ...

  9. 深入学习hbase:表,列族,列标识,版本和cell

    HBase是面向列的分布式的数据库,和传统的关系型数据库有很大的不同:物理模型和逻辑模型.这里我们要首先讲一下HBase数据库相关的区别于关系型数据库的几个基本概念:          表:HBase ...

  10. MVC4 过滤器使用和怎样控制全部action和部分action

    MVC中的过滤器分四种分别为:IActionFilter(动作过滤器), IAuthorizationFilter(授权过滤器), IExceptionFilter(异常过滤器), IResultFi ...