题目地址:http://poj.org/problem?id=2456

最大化最小值问题。二分牛之间的间距,然后验证。

 #include<cstdio>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stdbool.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
#define clr(x,y) memset(x,y,sizeof(x))
#define sqr(x) ((x)*(x))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define LL long long
#define INF 0x3f3f3f3f
#define A first
#define B second
const int N=+;
int n,m,
a[N]; bool check(int d)
{
int last=;
for(int i=;i<m;i++) {
int crt=last+;
while(crt<n && a[crt]-a[last]<d) {
crt++;
}
if(crt==n) return false;
last=crt;
}
return true;
} void solve()
{
sort(a,a+n);
int lb=,ub=INF; while(ub-lb>) {
int mid=(lb+ub)/;
if(check(mid)) {
lb=mid;
} else {
ub=mid;
}
}
printf("%d\n",lb);
} int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<n;i++) {
scanf("%d",&a[i]);
}
solve(); return ;
}

[POJ] 2456 Aggressive cows (二分查找)的更多相关文章

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

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

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

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

  3. POJ 2456 Aggressive cows(二分答案)

    Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22674 Accepted: 10636 Des ...

  4. poj 2456 Aggressive cows 二分 题解《挑战程序设计竞赛》

    地址 http://poj.org/problem?id=2456 解法 使用二分逐个尝试间隔距离 能否满足要求 检验是否满足要求的函数 使用的思想是贪心 第一个点放一头牛 后面大于等于尝试的距离才放 ...

  5. [poj 2456] Aggressive cows 二分

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

  6. POJ 2456 Aggressive cows ( 二分 && 贪心 )

    题意 : 农夫 John 建造了一座很长的畜栏,它包括N (2 <= N <= 100,000)个隔间,这些小隔间依次编号为x1,...,xN (0 <= xi <= 1e9) ...

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

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

  8. 二分搜索 POJ 2456 Aggressive cows

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

  9. POJ 2456 Agressive cows(二分)

    POJ 2456 Agressive cows 农夫 John 建造了一座很长的畜栏,它包括N (2≤N≤100,000)个隔间,这 些小隔间的位置为x0,...,xN-1 (0≤xi≤1,000,0 ...

随机推荐

  1. Swift中数组集合-b

    数组(Array)是一串有序的由相同类型元素构成的集合.数组中的集合元素是有序的,可以重复出现. 声明一个Array类型的时候可以使用下面的语句之一. var studentList1:Array&l ...

  2. GET方式的中文编码与解码

  3. rsyslog的ommsql模块如何连接MYSQL的非标准数据库端口?

    搞了我半小个时查找资料..最后,在一个官方文档中找到他... http://www.rsyslog.com/doc/ommysql.html Sample: The following sample ...

  4. GO的数组及切片

    感觉在向PYTHON学一些数组方面的功能. package main import "fmt" func main() { ]], , , , , , , , , } ] fmt. ...

  5. Unity 3D中的菜单项

    1.File菜单:主要是包含项目和场景的创建.保存以及输出等功能.2.Edit(编辑)菜单:只要包括对场景进行一系列的编辑以及环境设置操作等命令.3.Assets(资源)菜单:掌握资源在Unity中的 ...

  6. BZOJ3713: [PA2014]Iloczyn

    3713: [PA2014]Iloczyn Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 206  Solved: 112[Submit][Status ...

  7. bzoj1149

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1149 水题..... 直接BFS. #include<cstdio> #inclu ...

  8. Jquery回车键切换焦点方法(兼容各大浏览器)

    做项目时,客户要求能够用enter回车直接切换输入(焦点),当最后一个时候,直接提交信息. 第一想法就是,网上去copy一段代码直接用.但了百度.谷歌找了个遍,找到的代码80%以上都是一样的.有的代码 ...

  9. global.asax?app.config?webconfig??

    一.Global.asax 1.global.asax是什么? 一个文本文件,至于它包含写什么内容?顾名思义,global 肯定是掌管一个应用程序(application)的全局性的东西,例如应用程序 ...

  10. testng xml 示例

    TestNG的DTD检查文件:http://testng.org/testng-1.0.dtd.php 更多testng配置及说明,请移步http://testdoc.org/docmaster?pi ...