River Hopscotch
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 11155   Accepted: 4785

Description

Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to rock in a river. The excitement takes place on a long, straight river with a rock at the start and another rock at the end, L units away from the start (1 ≤ L ≤ 1,000,000,000). Along the river between the starting and ending rocks, N (0 ≤ N ≤ 50,000) more rocks appear, each at an integral distanceDi from the start (0 < Di < L).

To play the game, each cow in turn starts at the starting rock and tries to reach the finish at the ending rock, jumping only from rock to rock. Of course, less agile cows never make it to the final rock, ending up instead in the river.

Farmer John is proud of his cows and watches this event each year. But as time goes by, he tires of watching the timid cows of the other farmers limp across the short distances between rocks placed too closely together. He plans to remove several rocks in order to increase the shortest distance a cow will have to jump to reach the end. He knows he cannot remove the starting and ending rocks, but he calculates that he has enough resources to remove up to rocks (0 ≤ M ≤ N).

FJ wants to know exactly how much he can increase the shortest distance *before* he starts removing the rocks. Help Farmer John determine the greatest possible shortest distance a cow has to jump after removing the optimal set of M rocks.

Input

Line 1: Three space-separated integers: LN, and M 
Lines 2..N+1: Each line contains a single integer indicating how far some rock is away from the starting rock. No two rocks share the same position.

Output

Line 1: A single integer that is the maximum of the shortest distance a cow has to jump after removing M rocks

Sample Input

25 5 2
2
14
11
21
17

Sample Output

4
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN=;
int l,n,m;
int x[MAXN];
bool test(int d)
{
int cnt=;
int last=;
for(int i=;i<n;i++)
{
if(x[i]-last<d)
{
cnt++;
continue;
}
last=x[i];
}
if(l-last<d) return false;
return cnt<=m;
}
int main()
{
while(scanf("%d%d%d",&l,&n,&m)!=EOF)
{
for(int i=;i<n;i++)
{
scanf("%d",&x[i]);
}
sort(x,x+n);
int l=,r=0x3f3f3f3f;
while(r-l>)
{
int mid=(l+r)>>;
if(test(mid))
{
l=mid;
}
else
{
r=mid;
}
}
printf("%d\n",l);
}
return ;
}

POJ3258(最大化最小值)的更多相关文章

  1. POJ_2456_Agressive_cows_(二分,最大化最小值)

    描述 http://poj.org/problem?id=2456 有n个小屋,线性排列在不同位置,m头牛,每头牛占据一个小屋,求最近的两头牛之间距离的最大值. Aggressive cows Tim ...

  2. POJ3285 River Hopscotch(最大化最小值之二分查找)

    POJ3285 River Hopscotch 此题是大白P142页(即POJ2456)的一个变形题,典型的最大化最小值问题. C(x)表示要求的最小距离为X时,此时需要删除的石子.二分枚举X,直到找 ...

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

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

  4. hihocoder 二分·二分答案【二分搜索,最大化最小值】 (bfs)

    题目 这道题做了几个小时了都没有做出来,首先是题意搞了半天都没有弄懂,难道真的是因为我不打游戏所以连题都读不懂了? 反正今天是弄不懂了,过几天再来看看... 题意:一个人从1点出发到T点去打boss, ...

  5. codeforce 1070 E Getting Deals Done(二分求最大化最小值)

    Polycarp has a lot of work to do. Recently he has learned a new time management rule: "if a tas ...

  6. POJ2456(最大化最小值)

    Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10728   Accepted: 5288 ...

  7. 二分法的应用:最大化最小值 POJ2456 Aggressive cows

    /* 二分法的应用:最大化最小值 POJ2456 Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: ...

  8. POJ3258 River Hopscotch(二分最大化最小值)

    题目链接:http://poj.org/problem?id=3258 题意:给n个石头,起点和终点也是两个石头,去掉这石头中的m个,使得石头间距的最小值最大. 思路:二分石头间的最短距离,每次贪心地 ...

  9. poj3258 二分 最小值最大化问题

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10842   Accepted: 4654 ...

随机推荐

  1. WebLogic 12c 多节点Cluster静默安装

    WebLogic集群架构 Weblogic角色 AdminServer: 172.16.65.130 NodeServer: 172.16.65.131.172.16.65.132 版本 weblog ...

  2. mysql错误总结-ERROR 1067 (42000): Invalid default value for TIMESTAMP

    1. ERROR 1067 (42000): Invalid default value for 'FAILD_TIME'   (对TIMESTAMP  类型的子段如果不设置缺省值或没有标志not n ...

  3. 算法总结之 数组的partition调整 三个值的升序

    给定一个数组arr, 其中只可能有 0,1,2三个值,请实现arr排序 另一种问法: 有一个数组,只有红 蓝 黄 球,请事先红球全放在数组的左边,蓝球放中间,黄球放右边 另一种问法: 有一个数组,再给 ...

  4. linux下bwa和samtools的安装与使用

    bwa的安装流程安装本软体总共需要完成以下两个软体的安装工作:1) BWA2) Samtools 1.BWA的安装a.下载BWA (download from BWA Source Forge ) h ...

  5. 在环境变量里设置VI中TAB缩进

    终端上的tab键默认是缩进8个空格的(记住8个空格不等于一个tab, tab和空格不是一个概念) 一般设置vim的tab(制表符)的缩进的时候都这样:set tabstop=4 ” 表示让tab的宽度 ...

  6. BZOJ 1941 kd-tree

    模板题 题意说的可能有点不清楚 一开始的点必须在给定的n个点里面 所以枚举点 然后ask最大和最小值 估价函数中 最大值的写法和最小值不同 全部取max 而最小值在估价时 如果在某个点管辖的空间里 就 ...

  7. DecimalFormat数据格式函数

    DecimalFormat数据格式函数 class FormatDemo2{ public void format(String pattern, double value) { DecimalFor ...

  8. zoj3229 有源汇上下界最大流

    题意:有一个人每天给妹子拍照,每个妹子有最少拍照数,每天有最大拍照数,每天只能给某些特定的妹子拍照,求最大拍照数 题解:很容易看出来的有源汇上下界最大流,对于有源汇 的上下界最大流,我们按照无源汇的操 ...

  9. 大视野 1012: [JSOI2008]最大数maxnumber(线段树/ 树状数组/ 单调队列/ 单调栈/ rmq)

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 9851  Solved: 4318[Submi ...

  10. c++primer 第四章编程练习答案

    4.13.1 #include<iostream> struct students { ]; ]; char grade; int age; }; int main() { using n ...