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. QT应用程序设置图标

    一.纯Qt 1.下载图标:app.ico 2.新建记事本,输入:IDI_ICON1 ICON DISCARDABLE"app.ico":改变名字为jude.rc 3.将两个文件放在 ...

  2. JAVAWeb学习总结(3)

    JavaWeb学习总结(三)——Tomcat服务器学习和使用(二) 一.打包JavaWeb应用 在Java中,使用"jar"命令来对将JavaWeb应用打包成一个War包,jar命 ...

  3. MapReduce-边数据

    边数据 边数据(side data)是作业所需的额外的只读数据,以辅助处理主数据集.所面临的挑战在于如何使所有map或reduce任务(这些任务散布在集群内部)都能够方便而高效地使用边数据. 利用Jo ...

  4. HBase-建表(普通建表及预分区建表)

    package com.hbase.HBaseAdmin; import java.io.IOException; import org.apache.hadoop.conf.Configuratio ...

  5. ViewPagerAdapter

    ) { ; } } @Override public boolean isViewFromObject(View arg0, Object arg1) { return arg0 == arg1; } ...

  6. linux-RabbitMQ安装命令

    一.RabbitMQ 1.安装配置epel源    $ rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.no ...

  7. DP的四边形优化

    DP的四边形优化 一.进行四边形优化需要满足的条件 1.状态转移方程如下: m(i,j)表示对应i,j情况下的最优值. w(i,j)表示从i到j的代价. 例如在合并石子中: m(i,j)表示从第i堆石 ...

  8. SSIS的控制流之Foreach循环容器和序列容器

    上一篇介绍了For循环容器的使用.本篇将介绍Foreach循环容器和序列容器的使用. Foreach循环容器 Foreach循环容器定义包中的控制流.其循环的实现类似于编程语言中的Foreach循环结 ...

  9. srvany把程序作为Windows服务运行

    srvany.exe是什么? srvany.exe是Microsoft Windows Resource Kits工具集的一个实用的小工具,用于将任何EXE程序作为Windows服务运行.也就是说sr ...

  10. mac实用脚本

    安全清倒废纸篓(AppleScript) on run {input, parameters} set title to "安全清倒废纸篓" set trashIsEmptyMes ...