River Hopscotch

http://poj.org/problem?id=3258

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 21165   Accepted: 8791

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 Mrocks.

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).

Source

mid设为最短跳跃距离的最大值

 #include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std; int a[];
int L,N,M; bool erfen(int mid){
int sum=;
int tmp=a[];
int i=;
while(i<=N+){
if(a[i]-tmp<mid){
i++;
sum++;
}
else{
tmp=a[i++];
}
}
if(sum>M) return false;
return true;
} int main(){ cin>>L>>N>>M;
for(int i=;i<=N;i++){
cin>>a[i];
}
sort(a+,a+N+);
a[]=,a[N+]=L;
int LL=,RR=L,mid;
while(LL<=RR){
mid=LL+RR>>;
if(erfen(mid)){
LL=mid+;
}
else{
RR=mid-;
}
}
cout<<RR<<endl;
system("pause");
}

River Hopscotch的更多相关文章

  1. POJ 3258 River Hopscotch

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

  2. River Hopscotch(二分POJ3258)

    River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9263 Accepted: 3994 Descr ...

  3. POJ 3258 River Hopscotch (binarysearch)

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

  4. POJ3285 River Hopscotch(最大化最小值之二分查找)

    POJ3285 River Hopscotch 此题是大白P142页(即POJ2456)的一个变形题,典型的最大化最小值问题. C(x)表示要求的最小距离为X时,此时需要删除的石子.二分枚举X,直到找 ...

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

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

  6. POJ--3258 River Hopscotch (最小值最大化C++)

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

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

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

  8. bzoj1650 / P2855 [USACO06DEC]河跳房子River Hopscotch / P2678 (noip2015)跳石头

    P2855 [USACO06DEC]河跳房子River Hopscotch 二分+贪心 每次二分最小长度,蓝后检查需要去掉的石子数是否超过限制. #include<iostream> #i ...

  9. POJ3258 River Hopscotch 2017-05-11 17:58 36人阅读 评论(0) 收藏

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13598   Accepted: 5791 ...

随机推荐

  1. hdu 1278 逃离迷宫

    逃离迷宫 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. Linux下查看某个进程占用的CPU、内存

    1.用top命令指定固定的PID top -p 10997 查询指定进程的PID ps -ef | grep zookeeper jim 10997 1959 0 12月14 pts/2 00:00: ...

  3. java study3

    面向过程与面向对象 面向过程:必须了解整个过程,每个步骤互成因果关系,每个因果关系都构成一个步骤,多个步骤就构成了一个系统.因为存在因果关系,每隔步骤难以分离,非常紧密,当任何一步出现问题,将会影响到 ...

  4. jquery粘贴操作

    今天忘记记录一个点了,关于input字体默认浅色,聚焦变深的问题. 图一,默认浅色 图二,聚焦出现下拉框“最近搜索”记录,点击“程序员” 图三,input值变为“程序员”,颜色没有变深(复制粘贴也不变 ...

  5. vSphere client 登陆ESXI主机“您无权登录次服务器”

    vCenter安装在虚拟机上,安装好后想调整下内存,直接把虚拟机关闭了电源,突然一想服务器都被我关了,还拿什么修改内存,完蛋! 突然想起,在使用vCenter之前,都是用vsphere client ...

  6. linux下一个网卡配置多个ip【虚拟ip】

    Linux下配置网卡ip别名何谓ip别名?用windows的话说,就是为一个网卡配置多个ip.什么场合增加ip别名能派上用场?布网需要.多ip访问测试.特定软件对多ip的需要...and so on. ...

  7. http协议和https协议

    内容: 1.http协议介绍 2.https协议介绍 3.http协议和https协议对比 1.http协议介绍 (1)http协议是什么 1 一个传输协议,协议就是双方都遵守的规范. 2 为什么叫超 ...

  8. 怎样在本地windows安装和配置zookeeper

    Zookeeper是什么?有什么用? Zookeeper是一个分布式协调服务. 作用:为用户的分布式应用程序提供协调服务.  zookeeper在底层其实只提供了两个功能: 1.管理(存储,读取)用户 ...

  9. 创建类type (底层代码)

    类的创建时是用type 实现的 def __init__(self, name): self.name = name def fun(self): print("%s is talking' ...

  10. jq js 对象互转

    . DOM 对象转成 jQuery 对象 对于已经是一个 DOM 对象,只需要用 $() 把DOM对象包装起来,就可以获得一个 jQuery 对象了,$(DOM 对象) 注: var是定义变量 如: ...