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

时间:2023-02-17 20:53:02

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 ( ≤ L ≤ ,,,). Along the river between the starting and ending rocks, N ( ≤ N ≤ ,) more rocks appear, each at an integral distance Di from the start ( < 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 M rocks ( ≤ 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 : Three space-separated integers: L, N, and M
Lines ..N+: 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 : A single integer that is the maximum of the shortest distance a cow has to jump after removing M rocks

Sample Input


Sample Output


Hint

Before removing any rocks, the shortest jump was a jump of  from  (the start) to . After removing the rocks at  and , the shortest required jump is a jump of  (from  to  or from  to ).

Source

 
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
using namespace std;
#define N 50006
int dis[N];
int L,n,m;
bool solve(int min_dis){
int last=;
int cnt=;
for(int i=;i<=n+;i++){
if(dis[i]-dis[last]<=min_dis) cnt++;
else last=i;
} if(cnt>m) return true;
return false; }
int main()
{ while(scanf("%d%d%d",&L,&n,&m)==){
for(int i=;i<=n;i++){
scanf("%d",&dis[i]);
} if(n==m){
printf("%d\n",L);
continue;
} dis[]=;
dis[n+]=L;
sort(dis+,dis+n+);
int low=;
int high=L;
while(low<high){
int mid=(low+high)>>;
if(solve(mid)){
high=mid;
}
else{
low=mid+;
}
}
printf("%d\n",low);
}
return ;
}

poj 3258 River Hopscotch(二分搜索之最大化最小值)的更多相关文章

  1. &lbrack;ACM&rsqb; POJ 3258 River Hopscotch &lpar;二分,最大化最小值)

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

  2. poj 3258&quot&semi;River Hopscotch&quot&semi;&lpar;二分搜索&plus;最大化最小值问题&rpar;

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

  3. 二分搜索 POJ 3258 River Hopscotch

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

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

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

  5. POJ 3258 River Hopscotch(二分查找答案)

    一个不错的二分,注释在代码里 #include <stdio.h> #include <cstring> #include <algorithm> #include ...

  6. poj 3258 River Hopscotch 题解

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

  7. POJ 3258 River Hopscotch

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

  8. POJ 3258 River Hopscotch &lpar;binarysearch&rpar;

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

  9. POJ 3258 River Hopscotch&lpar;二分答案&rpar;

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

随机推荐

  1. 一个virtualbox开机即aborted的问题解决

    问题: 之前想装最新的virtualbox版本,从官网下载了virtualbox最新的5点几的版本,使用sudo dpkg -i *.deb进行安装的. 然而,在virtualbox中启动了ubunt ...

  2. C&num; 中 多线程同步退出方案 CancellationTokenSource

    C# 中提供多线程同步退出机制,详参对象: CancellationTokenSource CancellationTokenSource 中暂未提供复位操作,因此当调用Cancle 之后,若再次调用 ...

  3. 【android design】android常用设计资源

    一.概述 大部分程序员擅长开发,但是对于设计却知之甚少.这直接导致,程序员在初期开发出来的应用(大多为兴趣或实用导向)中看不中用.因此,有必要搜集整合一些设计资源,这样既能减轻程序员在设计上所耗费的时 ...

  4. Newtonsoft&period;Json&period;dll序列化为json,null值自动过滤

    var jSetting = new JsonSerializerSettings {NullValueHandling = NullValueHandling.Ignore}; var json = ...

  5. HDU4521&plus;线段树&plus;dp

    题意:在一个序列中找出最长的某个序列.找出的序列满足题中的条件. 关键:对于 第 i 个位置上的数,要知道与之相隔至少d的位置上的数的大小.可以利用线段树进行统计,查询.更新的时候利用dp的思想. / ...

  6. JQuery 选择某个td中第二个a标签 控制特殊样式

    a标签没有disabled属性,那么当我们想禁用a标签的点击事件的时候按照下面方法设置. 下面是html代码: <a id="entry” class="entry&quot ...

  7. The Preliminary Contest for ICPC China Nanchang National Invitational and International Silk-Road Programming Contest

    打网络赛 比赛前的准备工作要做好 确保 c++/java/python的编译器能用 打好模板,放在桌面 A. PERFECT NUMBER PROBLEM #include <cstdio&gt ...

  8. &lbrack;javaEE&rsqb; HTTP协议总结

    OSI网络7层协议 物理层 ==> 数据链路层 ==> 网络层ip ==> 传输层 TCP UDP ==>会话层 ==>表示层 ==> 应用层 HTTP FTP S ...

  9. 剥开比原看代码11:比原是如何通过接口&sol;create-account创建帐户的

    作者:freewind 比原项目仓库: Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchai ...

  10. 如何查看Isilon的节点的CPU的信息?

    使用Isilon自带的命令 isi_hw_status 使用如下的命令 dmidecode --type processor 笔者只是想了解一下F800的CPU有多少个core.上面的命令都可以获得这 ...