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 2
2
14
11
21
17

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)
 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
#include<string>
using namespace std;
#define MAXN 50001
#define INF 0x3f3f3f3f
/*
在一个有序序列中移除M个元素:
求元素之间最短距离最大能增大多少
先求出当前最短距离
二分查找当前最短-最终最短 找到通过移除M个元素最大的最短距离
关键还是check函数 在移除M个情况下,最短跳跃x能否到达终点
*/
int a[MAXN], L, n, m, tmp;
bool check(int mid)
{
int i, before = , cnt = ;
for (i = ; i <= n + ; i++)
{
if (a[i] - a[before] >= mid)//这块用于判断是否去掉石头
{
before = i;
}
else
{
cnt++;
if (cnt > m)
return false;
}
}
return true;
}
int main()
{
while (scanf("%d%d%d", &L, &n, &m) != EOF)
{
a[] = ;
for (int i = ; i < n; i++)
{
scanf("%d", &a[i]);
}
a[n+] = L;
sort(a, a + n+);
int beg = , end = L*,ans = ;
while (beg <= end)
{
int mid = (beg + end) / ;
if (check(mid))
{
ans = mid;
beg = mid + ;
}
else
end = mid - ;
}
printf("%d\n", ans);
}
return ;
}

POJ River Hopscotch 二分搜索的更多相关文章

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

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

  2. 二分搜索 POJ 3258 River Hopscotch

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

  3. E - River Hopscotch POJ - 3258(二分)

    E - River Hopscotch POJ - 3258 Every year the cows hold an event featuring a peculiar version of hop ...

  4. POJ 3258 River Hopscotch

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

  5. POJ 3258 River Hopscotch (binarysearch)

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

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

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

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

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

  8. 【POJ - 3258】River Hopscotch(二分)

    River Hopscotch 直接中文 Descriptions 每年奶牛们都要举办各种特殊版本的跳房子比赛,包括在河里从一块岩石跳到另一块岩石.这项激动人心的活动在一条长长的笔直河道中进行,在起点 ...

  9. POJ 3258:River Hopscotch 二分的好想法

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9326   Accepted: 4016 D ...

随机推荐

  1. 【转载】Sybase数据库服务器端安装

    sybase数据库的安装分为服务器端和客户端,本文先介绍一下服务器端的安装. 1.和其他程序一样,双击setup.exe.   2.出现欢迎界面,直接点击next即可.   3.下面选择相应国家的协议 ...

  2. 等价表达式 2005年NOIP全国联赛提高组(栈模拟)

    P1054 等价表达式 题目描述 明明进了中学之后,学到了代数表达式.有一天,他碰到一个很麻烦的选择题.这个题目的题干中首先给出了一个代数表达式,然后列出了若干选项,每个选项也是一个代数表达式,题目的 ...

  3. [App Store Connect帮助]一、 App Store Connect 使用入门(3)首页概述

    从首页可以访问 App Store Connect 的各个部分.您仅能访问每个部分中与您的用户职能相关联的功能. [提示]通过点按任何页面顶部的“App Store Connect”,您可以随时返回 ...

  4. 微信小程序之商品发布+编辑功能(多图片上传功能)

    小程序的商品发布页面:功能有多图片上传 遇到的问题记录一下:1.uploadFile成功之后返回的参数是json字符串,一定要用JSON.parse转换为object格式 2.因为商品发布和编辑都是在 ...

  5. Hadoop Hive概念学习系列之hive里如何显示当前数据库及传参(十九)

    这个小知识点,看似简单,用处极大. $ hive --hiveconf hive.cli.print.current.db=true $ hive --hiveconf hive.cli.print. ...

  6. Mysql(Innodb)如何避免幻读

    Mysql(Innodb)如何避免幻读 有意思 MySQL InnoDB支持三种行锁定方式: 行锁(Record Lock):锁直接加在索引记录上面,锁住的是key. 间隙锁(Gap Lock):锁定 ...

  7. MyBatis ((一对多和多对一配置)实现持久化操作 之二)

    注: 此文中的实体类还是沿用上一章的Emp和Dept两个类 还是老样子,不细说 直接上代码 01.在emp.xml中  配置和Dept的多对一的相关信息 <?xml version=" ...

  8. 定制UVM Messages(参考)

    UVM的Messages机制有些时候很繁琐,很多时候希望能够在UVM messages的基础上做一些个人化的订制,这里给出来一个找到的例子作为参考. my_macros.sv:    `define ...

  9. JS高级——作用域链

    基本概念 1.只要是函数就可以创造作用域 2.函数中又可以再创建函数 3.函数内部的作用域可以访问函数外部的作用域 4.如果有多个函数嵌套,那么就会构成一个链式访问结构,这就是作用域链 <scr ...

  10. JS——offset

    1.offsetWidth.offsetHeight返回盒子宽度和高度,包括padding与border,不包括margin 2.offsetLeft.offsetTop返回盒子距离定位盒子的x轴方向 ...