题目链接:

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. poj 1001 字符串乘法以及处理精度问题

    #include<iostream> #include<cstring> using namespace std; int main() { string r; int n,d ...

  2. Zero Sum Subarray

    Given an integer array, find a subarray where the sum of numbers is zero. Your code should return th ...

  3. vue vue-resource网络请求

    在使用get/post 网络请求,需要下载插件 "vue-resource" npm install vue-resource -s 在路由要导入及注册 import Vue fr ...

  4. pl/sql 如何配置连接远程一个或多个数据库

    参考链接 https://blog.csdn.net/yy_love_my/article/details/45720277

  5. Mybatis学习笔记7 - select查询的相关属性使用

    1.当接口的返回类型是集合List时,resultType要写集合中元素的类型 示例如下: 接口定义: package com.mybatis.dao; import com.mybatis.bean ...

  6. poi 详细demo

    import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IO ...

  7. sublime text2 for mac 实现json格式化

    问题描述: 网上拿下来的一大段json格式的字符串,放到sublime上格式化成json的标准格式 数据截图如下: 解决问题: 网络上搜了一下,大部分都是说要装pretty json插件 先来看看自己 ...

  8. 性能测试工具LoadRunner18-LR之Controller 集合点

    含义 当通过controller虚拟多个用户执行该脚本时.用户的启动或运行步骤不一定是同步的.集合点是在脚本的某处设置一个标记.当有虚拟用户运行到这个标记时,停下等待,直到所有用户都达到这个标记时,再 ...

  9. (转)AIX下的MPIO、RDAC、SDDPCM多路径软件操作 (AIX下的MPIO,查看AIX下hdisk与盘柜卷lun的对应关系)

    AIX下的MPIO.RDAC.SDDPCM多路径软件操作 (AIX下的MPIO,查看AIX下hdisk与盘柜卷lun的对应关系) 原文:http://blog.163.com/huangbao_007 ...

  10. 04-spring中的aop演示

    1 xml配置 1 导包 2 准备对象 package www.test.service; public interface UserService { public abstract void ad ...