题目传送门

 /*
二分搜索:搜索安排最近牛的距离不小于d
*/
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
int x[MAXN];
int n, m; bool check(int d) {
int last = ;
for (int i=; i<=m-; ++i) {
int cur = last + ;
while (cur <= n && x[cur] - x[last] < d) cur++;
if (cur == n + ) return false;
last = cur;
}
return true;
} int main(void) { //POJ 2456 Aggressive cows
//freopen ("POJ_2456.in", "r", stdin); while (scanf ("%d%d", &n, &m) == ) {
for (int i=; i<=n; ++i) {
scanf ("%d", &x[i]);
} sort (x+, x++n);
int l = , r = INF;
while (l + < r) {
int mid = (l + r) >> ;
if (check (mid)) l = mid;
else r = mid;
}
printf ("%d\n", l);
} 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 (二分 基础)

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

  3. POJ 2456 Aggressive cows (二分)

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

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

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

  5. POJ 2456 Aggressive cows

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

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

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

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

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

  8. poj 2456 Aggressive cows 贪心+二分

    Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25944   Accepted: 11982 ...

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

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

随机推荐

  1. 图解Elasticsearch中的_source、_all、store和index属性

    https://blog.csdn.net/napoay/article/details/62233031

  2. HDU - 2059 龟兔赛跑(多阶段决策dp)

    http://acm.hdu.edu.cn/showproblem.php?pid=2059 初始把起点和终点也算做充电站,设dp[i]是到第i个充电站的最短时间,那么dp[n+1]即是乌龟到达终点的 ...

  3. 1sting 大数 递推

    You will be given a string which only contains ‘1’; You can merge two adjacent ‘1’ to be ‘2’, or lea ...

  4. Apache 使用localhost(127.0.0.1)可以访问,使用本机IP(局域网)不能访问

    本机ip是:192.168.1.25,输入后提示: Forbidden You don't have permission to access / on this server 对于此问题的解决办法, ...

  5. [bzoj2287][poj Challenge]消失之物_背包dp_容斥原理

    消失之物 bzoj-2287 Poj Challenge 题目大意:给定$n$个物品,第$i$个物品的权值为$W_i$.记$Count(x,i)$为第$i$个物品不允许使用的情况下拿到重量为$x$的方 ...

  6. COGS2479(四维偏序)

    题意:给定一个有n个元素的序列,元素编号为1~n,每个元素有三个属性a,b,c,求序列中满足i<j且ai<aj且bi<bj且ci<cj的数对(i,j)的个数. 分析:cdq分治 ...

  7. spring history &design Philosophy

    Spring简介 Spring是一个开源框架,它由Rod Johnson创建.它是为了解决企业应用开发的复杂性而创建的.Spring使用基本的JavaBean来完成以前只可能由EJB完成的事情.然而, ...

  8. SHARP AR-2048D/2348D

    http://www.sharp.cn/printer/AR-2048D%7C2348D/support/download.html

  9. CentOS 7 es搭建测试

    搭建本地yum repo pass 指定特定repo 安装,比如安装wget.(指定特定repo 是为了从最快的repo安装) yum --disablerepo=\* --enablerepo=os ...

  10. hadoop2.2集群搭建问题只能启动一个datanode问题

    按照教程http://cn.soulmachine.me/blog/20140205/搭建总是出现如下问题: 2014-04-13 23:53:45,450 INFO org.apache.hadoo ...