River Hopscotch
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 15273   Accepted: 6465

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 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).
这是最脑抽的一次~~~
最大值最小化,最小值最大化都是典型的二分法!!!重点必考,圈起来!!!
要养成总结题型的习惯,没有这个习惯就会很傻的去模拟,结果半天过不了。
理清思路其实不难,要知道二分什么,有什么情况。
这道题有道类似的分钱题,题意是 给一组数,划/ 分成m组。类似的,当cnt==m时,归为偏小
#include<iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
int a[50005];
int main()
{
int l,m,n;
while(~scanf("%d%d%d",&l,&n,&m))
{ for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]); }
a[0]=0;
a[n+1]=l;
sort(a+1,a+n+1);
int mid,low=0,r=l;
while(r>=low)
{
int tem=0,c=0;
mid=(low+r)/2;
for(int i=1;i<=n+1;i++)
{
if(mid>=a[i]-a[tem])
c++;
else
tem=i;
}
if(c>m)
r=mid-1;
else
low=mid+1;
// cout<<low<<" "<<mid<<" "<<r<<endl;
}
printf("%d\n",low);
}
}

  

POJ--3258 River Hopscotch (最小值最大化C++)的更多相关文章

  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. [ACM] POJ 3258 River Hopscotch (二分,最大化最小值)

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

  4. poj 3258 River Hopscotch 题解

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

  5. POJ 3258 River Hopscotch

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

  6. POJ 3258 River Hopscotch (binarysearch)

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

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

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

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

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

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

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

随机推荐

  1. 项目记事【SpringMVC-1】:后台接收前端传来的JSON,并转成对象

    背景: 最近项目中使用SpringMVC,需要从前端接收JSON格式的请求,在后端自动转成一个与JSON格式相同的对象. 由于是一个老项目,Spring的版本是3.2.7. 问题1:POST or G ...

  2. 细说 Azure Storage 的冗余策略

    当我们想要把应用搬到云端的时候,首先要关注的便是数据的安全性.当然所有的云服务厂商都会对用户数据承诺一个非常高的安全性,但万一出现意外呢?我们是不是还要有适当的应对方案?比如今年的3月8日晚间,Azu ...

  3. 用PE安装操作系统时:无法创建新的系统分区 也无法定位现有系统分区 的解决办法

    借助U盘的用PE安装操作系统时系统提示:无法创建新的系统分区 也无法定位现有系统分区 的解决办法... --------------------------------- 具体原因是安装时加载到安装程 ...

  4. java注释中使用注解@see

    缘起 在写java时,有时需要写注释,而为了更好的描述,需要引用和参考其他代码.为了让阅读者更好的体验,javadoc中支持链接跳转,这就需要用到注解@see. @see用法 注解@see可以在注释中 ...

  5. Markov不等式,Chebyshev不等式

    在切诺夫界的证明中用到了Markov不等式,证明于此~顺便把Chebyshev不等式也写上了

  6. JDBC的链接及封装

    导入 mysql 的jar包 jar包:可以直接拿来用,又不想我们看到源代码   sql语句 一定注意:当update,delete时 一定注意where 条件,一定要写!!! public stat ...

  7. CODE大全给你推荐几个免费的leapftp 注册码

    leapftp 2.7.6 注册码, Name: Kmos/CiA in 1999 s/n: MOD1-MO2D-M3OD-NOPQ LeapFTP2.7.5 注册名:swzn 注册码:214065- ...

  8. Intelli IDEA学习系列之快捷键篇

    Intelli IDEA学习系列之快捷键篇 IDEA简介: IDEA 全称IntelliJ IDEA,是java语言开发的集成环境,IntelliJ在业界被公认为最好的java开发工具之一,尤其在智能 ...

  9. Java对象的创建

    学了很久的java,是时候来一波深入思考了.比如:对象是如何在JVM中创建,并且被使用的.本文主要讲解下new对象的创建过程.要想更深入的了解建议去认认真真的看几遍<深入理解Java虚拟机> ...

  10. JavaScript 30 - 2 学习笔记

    学习JavaScirpt30的笔记! 有意思! 2------->   CSS clock 效果是这样的.... 这是改良过后的 版本.... 话不多说,直接来看代码. 首先是html部分 &l ...