题目地址: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. 对拍 For Linux

    #!/bin/sh g++ -g gene.cpp -o gene g++ -g a.cpp -o a g++ -g b.cpp -o b while true; do  ./gene > in ...

  2. 使用NUnit进行项目的单元测试

    using System; using System.Collections; using System.Collections.Generic; using NUnit.Framework; nam ...

  3. ANDROID (eclipse)开发常见问题及解决办法汇总

    1.ANDROID 在eclipse中没有出现AVD的解决方法(转)如果android安装正确的话,但是eclipse里面的导航条就是没有AVD 可以通过「Window」⇒「Customize Per ...

  4. logstash tag使用说明

    zjtest7-frontend:/usr/local/logstash-2.3.4/config# cat stdin04.conf input { stdin { } } filter { # d ...

  5. Xmind 快捷键

    Xmind 快捷键 快捷键(Windows) 快捷键(Mac) 描述 Ctrl+N Command+N 建立新工作簿 Ctrl+O Command+O 开启工作簿 Ctrl+S Command+S 储 ...

  6. netstat命令, netstat指令在windows和linux有什么不同

    查看当前tcp监听端口[op@TIM html]$ netstat -nltp(Not all processes could be identified, non-owned process inf ...

  7. spring 配置文件XSD地址

    这边部署不能访问外网,所以sping配置文件里的XSD地址要改一下象  http://www.springframework.org/schema/beans/spring-beans-2.0.xsd ...

  8. 用Nginx实现Session共享的均衡负载

    前言 大学三年多,也做个几个网站和APP后端,老是被人问到,如果用户多了服务器会不会挂,总是很尴尬的回答:“哈哈,我们的用户还少,到了服务器撑不住的时候,估计都上市了吧”.说是这么说,但是对于有强迫症 ...

  9. Android 读取手机SD卡根目录下某个txt文件的文件内容

    1.先看activity_main.xml文件: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/and ...

  10. Annotation(四)——Struts2注解开发

    Hibernate和Spring框架的开发前边总结了,这次看一下流行的MVC流程框架Struts2的注解开发吧.Struts2主要解决了从JSP到Action上的流程管理,如何进行Uri和action ...