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 ( ≤ L ≤ ,,,). Along the river between the starting and ending rocks, N ( ≤ N ≤ ,) more rocks appear, each at an integral distance Di from the start ( < 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 M rocks ( ≤ 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 : Three space-separated integers: L, N, and M
Lines ..N+: 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 : A single integer that is the maximum of the shortest distance a cow has to jump after removing M rocks

Sample Input


Sample Output


Hint

Before removing any rocks, the shortest jump was a jump of  from  (the start) to . After removing the rocks at  and , the shortest required jump is a jump of  (from  to  or from  to ).

Source

 
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
using namespace std;
#define N 50006
int dis[N];
int L,n,m;
bool solve(int min_dis){
int last=;
int cnt=;
for(int i=;i<=n+;i++){
if(dis[i]-dis[last]<=min_dis) cnt++;
else last=i;
} if(cnt>m) return true;
return false; }
int main()
{ while(scanf("%d%d%d",&L,&n,&m)==){
for(int i=;i<=n;i++){
scanf("%d",&dis[i]);
} if(n==m){
printf("%d\n",L);
continue;
} dis[]=;
dis[n+]=L;
sort(dis+,dis+n+);
int low=;
int high=L;
while(low<high){
int mid=(low+high)>>;
if(solve(mid)){
high=mid;
}
else{
low=mid+;
}
}
printf("%d\n",low);
}
return ;
}

poj 3258 River Hopscotch(二分搜索之最大化最小值)的更多相关文章

  1. [ACM] POJ 3258 River Hopscotch (二分,最大化最小值)

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6697   Accepted: 2893 D ...

  2. poj 3258"River Hopscotch"(二分搜索+最大化最小值问题)

    传送门 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有 N 块岩石,从中去掉任意 M 块后,求相邻两块岩石最小距离最大是多少? 题解 ...

  3. 二分搜索 POJ 3258 River Hopscotch

    题目传送门 /* 二分:搜索距离,判断时距离小于d的石头拿掉 */ #include <cstdio> #include <algorithm> #include <cs ...

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

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9923   Accepted: 4252 D ...

  5. POJ 3258 River Hopscotch(二分查找答案)

    一个不错的二分,注释在代码里 #include <stdio.h> #include <cstring> #include <algorithm> #include ...

  6. poj 3258 River Hopscotch 题解

    [题意] 牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离, 现在去掉M块石头,要求去掉M块石头后,剩下的石头之间以及石头与河岸的最小距离的最大值 ...

  7. POJ 3258 River Hopscotch

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11031   Accepted: 4737 ...

  8. POJ 3258 River Hopscotch (binarysearch)

    River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5193 Accepted: 2260 Descr ...

  9. POJ 3258 River Hopscotch(二分答案)

    River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 21939 Accepted: 9081 Desc ...

随机推荐

  1. [Redux] Implementing combineReducers() from Scratch

    The combineReducers function we used in previous post: const todoApp = combineReducers({ todos, visi ...

  2. C#读取注册表

    //1.向注册表中写信息using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"", true)){ if (key ...

  3. hdu5067Harry And Dig Machine(TSP旅行商问题)

    题目链接: huangjing 题意:给出一幅图.图中有一些点,然后从第1个点出发,然后途径全部有石头的点.最后回到原点,然后求最小距离.当初作比赛的时候不知道这就是旅行商经典问题.回来学了一下. 思 ...

  4. linux shell 切换到ROOT用户

    #!/bin/bash expect -c "        set timeout 1000        spawn /bin/su - root         expect \&qu ...

  5. Java和C++的不同

    现在一边继续深入C++,一边学习Java,为了学习得更加透彻,不断比较两者之间的不同,以后会慢慢继续增加. 1.在多态的实现上,C++需要利用关键字virtual,而Java不需要,因为在Java中, ...

  6. Android 自定义控件玩转字体变色 打造炫酷ViewPager指示器

    1.概述 本篇博客的产生呢,是因为,群里的哥们暖暖给我发了个效果图,然后问我该如何实现顶部ViewPager指示器的字体变色,该效果图是这样的: 大概是今天头条的app,神奇的地方就在于,切换View ...

  7. ArcGis ToolBar为灰色

    问题描述:添加完导航按钮,测试时发现按钮一直都是灰色的,不可用状态. 可能原因:跟控件添加的顺序有关,导致toolbar跟map控件无法正确关联. 解决方案:删掉toolBar,重新添加.

  8. C# List 泛型用法

    List 类是 ArrayList 类的泛型等效类,某些情况下,用它比用数组和 ArrayList 都方便. 我们假设有一组数据,其中每一项数据都是一个结构. public struct Item{  ...

  9. 矩阵链乘 hrbust 1600

    #include<string.h> //区间dp的思想#include<iostream> //将一个区间分成两段,将每一段当成是一个矩阵#include<stdio. ...

  10. Go语言之defer

    defer语句被用于预定对一个函数的调用.我们把这类被defer语句调用的函数称为延迟函数.注意,defer语句只能出现在函数或方法的内部. 一条defer语句总是以关键字defer开始.在defer ...