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

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 distance Di 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 2214112117

Sample Output

4

Hint

Before removing any rocks, the shortest jump was a jump of 2 from 0 (the start) to 2. After removing the rocks at 2 and 14, the shortest required jump is a jump of 4 (from 17 to 21 or from 21 to 25).

Source

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=50050;
int len,n,m;
int a[maxn];
int binarysearch(int low,int high)
{
    int mid;
    while(low<=high)
    {
        mid=(low+high)/2;
        int s=0,e=1;
        int cnt=0;
        while(e<n)
        {
            if(a[e]-a[s]>=mid)
            {
                s=e; e++;
            }
            else
            {
                e++; cnt++;
            }
        }
//cout<<low<<","<<mid<<","<<high<<endl;
//cout<<"-->"<<cnt<<endl;
        if(cnt>m)
        {
            high=mid-1;
        }
        else
        {
            low=mid+1;
        }
    }
    return high;
}
int main()
{
    cin>>len>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a;
    a[0]=0;
    a[n+1]=len;
    n=n+2;
    sort(a,a+n);
    int minn=len;
    for(int i=1;i<n;i++)
    {
        minn=min(minn,a-a[i-1]);
    }
    cout<<binarysearch(minn,len)<<endl;
    return 0;
}

POJ 3258 River Hopscotch (binarysearch)的更多相关文章

  1. 二分搜索 POJ 3258 River Hopscotch

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

  2. POJ 3258 River Hopscotch

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

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

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

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

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

  5. poj 3258 River Hopscotch 题解

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

  6. POJ 3258 River Hopscotch(二分法搜索)

    Description Every year the cows hold an event featuring a peculiar version of hopscotch that involve ...

  7. poj 3258 River Hopscotch(二分+贪心)

    题目:http://poj.org/problem?id=3258 题意: 一条河长度为 L,河的起点(Start)和终点(End)分别有2块石头,S到E的距离就是L. 河中有n块石头,每块石头到S都 ...

  8. POJ 3258 River Hopscotch 二分枚举

    题目:http://poj.org/problem?id=3258 又A一道,睡觉去了.. #include <stdio.h> #include <algorithm> ]; ...

  9. poj 3258 River Hopscotch(二分搜索之最大化最小值)

    Description Every year the cows hold an ≤ L ≤ ,,,). Along the river between the starting and ending ...

随机推荐

  1. Java 第一天

    环境变量设置(以JDK1.7为例) CLASSPATH=.\;C:\Program Files\Java\jdk1.7.0_45\lib\dt.jar;C:\Program Files\Java\jd ...

  2. 第十七章 调试及安全性(In .net4.5) 之 程序诊断

    1. 概述 生产环境中的程序,也是不能保证没有问题的.为了能方便的找出问题,.net提供了一些特性来进行程序诊断. 这些特性包括:logging.tracing .程序性能分析(profiling) ...

  3. 使用eclipse开发

    Eclipse下载地址:http://www.eclipse.org/ 下载后进行解压缩,点击eclipse.exe即可使用eclipse workspace:工作区      Project:项目 ...

  4. java获取数据库里表的名字

    一.Java方法 // 得到当前数据库下所有的表名 public void getTableNameByCon(Connection con) { try { DatabaseMetaData met ...

  5. 算法系列6《MAC》

    1. 简介 MAC是使用命令的所有元素(包括命令头)产生的.一条命令的完整性,包括命令数据域(如果存在的话)中的数据元,通过安全报文传送得以保证.按照如下的方式使用单重或三重DEA加密方式产生MAC: ...

  6. android开发系列之消息机制

    最近接触到一个比较有挑战性的项目,我发现里面使用大量的消息机制,现在这篇博客我想具体分析一下:android里面的消息到底是什么东西,消息机制到底有什么好处呢? 其实说到android消息机制,我们可 ...

  7. 使用ViewSwitcher和ViewFlipper在不同布局中切换

    xml布局: <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:androi ...

  8. 基于jquery的页面代码的优化

    高亮显示,选中的文字链接 显示效果如下 默认选择“通知公告”效果 通知公告 学院动态 行业动态       选择“学院动态”效果 通知公告 学院动态 行业动态       选择“行业动态”效果 通知公 ...

  9. [转]40多个关于人脸检测/识别的API、库和软件

    [转]40多个关于人脸检测/识别的API.库和软件 http://news.cnblogs.com/n/185616/ 英文原文:List of 40+ Face Detection / Recogn ...

  10. 68.vivado与modelsim的关联以及器件库编译

    vivado软件中也自带仿真工具,但用了几天之后感觉仿真速度有点慢,至少比modelsim慢挺多的.而modelsim是我比较熟悉的一款仿真软件,固然选它作为设计功能的验证.为了将vivado和mod ...