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. linux—find指令常见用法示例

    Linux下find命令在目录结构中搜索文件,并执行指定的操作.Linux下find命令提供了相当多的查找条件,功能很强大.由于find具有强da的功能,所以它的选项也很多,其中大部分选项都值得我们花 ...

  2. 《Java从入门到放弃》入门篇:hibernate查询——HQL

    不知不觉又到了hibernate的最后一篇了,只感觉时光飞逝~,岁月如梭~! 转眼之间,我们就···························,好吧,想装个X,结果装不下去了,还是直接开始吧· ...

  3. node.js之setTimeout()、clearTimeout()与 setInterval()与clearInterval()

    1.setTimeout函数与clearTimeout函数 setTimeout(cb,ms,[arg],[...])延时一定时间执行回调函数该函数中cb参数为必填函数,为需要执行的回调函数ms为经过 ...

  4. LinkedList之modCount和expectedModCount

    modCount和expectedModCount是用于表示修改次数的,其中modCount表示集合的修改次数,这其中包括了调用集合本身的add方法等修改方法时进行的修改和调用集合迭代器的修改方法进行 ...

  5. 【Hadoop】执行start-dfs.sh出错

    问题1:hadoop2.7.3部署警告: Unable to load native-hadoop library for your platform 解决办法: 1.编辑hadoop-env.sh ...

  6. 【Ubuntu 16】显示管理器lightdm

    lightdm是一个全新的轻量级的显示管理器,在Ubuntu16.04上面已经使用. 从图形界面进入到命令行界面 systemctl disable lightdm.service 从命令行进入到图形 ...

  7. APUE 1 -- Unix数据结构

    Unix 类操作系统支持不同进程间共享文件.对于所有的I/O,内核使用3种数据结构来表示一个打开的文件. 进程表.每个进程在进程表中有其相应的入口.文件结构中,每个进程表的入口是文件描述符表,每个文件 ...

  8. Win7怎么显示文件的后缀名

    Win7怎么显示文件的后缀名.. --------------- -------------- --------------- -------------- --------------- ----- ...

  9. 8.20.1 图形化:弹窗JOptionPane

    最近在做swing程序中遇到使用消息提示框的,JOptionPane类其中封装了很多的方法. 很方便的,于是就简单的整理了一下. 1.1 showMessageDialog 显示一个带有OK 按钮的模 ...

  10. Requests抓取有道翻译结果

    Requests比urllib更加方便,抓取有道翻译非常的简单. import requests class YouDao():     def __init__(self,parm):        ...