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

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

【题意】

在起点和终点之间,有 N 块岩石(不含起点和终点的岩石),至多可以从起点和终点之间移走 M 块岩石(不能移走起点和终点的岩石),求移走岩石后最短跳跃距离的最大值

【分析】

[NOIP2015跳石头(原题)]

直接二分,具体详见代码

【代码】

#include<cstdio>
#include<algorithm>
#include<iostream>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
using namespace std;
inline int read(){
int x=,f=;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*+ch-'0';ch=getchar();}
return x*f;
}
const int N=1e5+;
int ans,n,m,L,d[N];
inline bool check(int now){
int res=,p=;//p为前一个石头到指向石头的距离
for(int i=;i<=n;i++){
if(d[i]-p<now){//如果第i个石头到前一个石头的距离小于假设的答案
res++;//该石头可以搬走
}
else{//如果大于(即满足条件)
p=d[i];//则保留该石头,并将p记录 下一个石头到该石头的距离
}
}
return res<=m;
}
int main(){
L=read(),n=read(),m=read();
for(int i=;i<=n;i++) d[i]=read();d[++n]=L;//我们假设在终点处有第n+1个石头,则他到起点的距离为L
sort(d+,d+n+);//保证石头有序
int l=,r=L,mid;
while(l<=r){
mid=l+r>>;
if(check(mid)){//说明二分结果小了,要向右二分
ans=mid;//记录答案
l=mid+;
}
else{
r=mid-;//说明结果大了,要向左二分
}
}
printf("%d\n",ans);
return ;
}

 

 

POJ 3258 River Hopscotch(二分答案)的更多相关文章

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

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

  2. poj 3258 River Hopscotch(二分+贪心)

    题目:http://poj.org/problem?id=3258 题意: 一条河长度为 L,河的起点(Start)和终点(End)分别有2块石头,S到E的距离就是L. 河中有n块石头,每块石头到S都 ...

  3. POJ 3258 River Hopscotch 二分枚举

    题目:http://poj.org/problem?id=3258 又A一道,睡觉去了.. #include <stdio.h> #include <algorithm> ]; ...

  4. poj 3258 River Hopscotch 二分

    /** 大意:给定n个点,删除其中的m个点,其中两点之间距离最小的最大值 思路: 二分最小值的最大值---〉t,若有距离小于t,则可以将前面的节点删除:若节点大于t,则继续往下查看 若删除的节点大于m ...

  5. 二分搜索 POJ 3258 River Hopscotch

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

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

    嗯... 题目链接:http://poj.org/problem?id=3258 一道很典型的二分答案的题目,和跳石头太像了!! 这道题的题目很显然,求最小中的最大值,注意这道题石头的位置不是从小到大 ...

  7. POJ 3258 River Hopscotch (最大最小距离)【二分】

    <题目链接> 题目大意:现在有起点和终点两个石块,这两个石块之间有N个石块,现在对这N个石块移除M个石块,使得这些石块之间的最短距离最大,注意,起点和终点这两个石块不能被移除. 解题分析: ...

  8. POJ 3258 River Hopscotch

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

  9. poj 3258 River Hopscotch 题解

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

随机推荐

  1. Hbuilder MUI里面使用java.net.URL发送网络请求,操作cookie

    1. 引入所需网络请求类: var URL = plus.android.importClass("java.net.URL"); var URLConnection = plus ...

  2. 新建maven指定jdk版本-eclipse新建maven项目报错The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path的解决方案

    具体表现为: 使用Eclipse+Maven建立了一个Javaweb工程,JSP页面顶端出现“红色”的报错信息:The superclass "javax.servlet.http.Http ...

  3. 阿里云Centos6.9安装图形化界面

    yum -y groupinstall "X Window System" "Chinese Support" "Desktop"

  4. 软件设计模式之代理模式(JAVA)

    貌似停笔了近半个月了,实在不该啊,新的一年,时刻让自己归零. Back To Zero,就从这篇文章拉开今年的序幕吧. 这篇文章准备介绍下有关代理模式的基本概念和静态代理.动态代理的优缺点及使用方法( ...

  5. 基于ThinkPHP的在线编辑器调用

    开源的在线编辑器有很多,比如FCKEditor,UEditor,Kindeditor等,调用方式也都大同小异 下面列举UEditor在线编辑器插件在ThinkPHP里面的应用 1.Ueditor下载地 ...

  6. 【WP8】自定义EventAggregator

    MVVM模式实现了ViewModel和View的分离,但是有很多时候我们需要进行页面间通信 比如,我们在设置界面修改了某个项的值,需要同步到主页面,让主页面做相关的逻辑,由于每个页面对应一个ViewM ...

  7. 好用的图片缩放JS

    <!DOCTYPE HTML> <meta charset="UTF-8"> <head> <script src="jquer ...

  8. MYSQL列中的数据以逗号隔开,如何查询

    FROM `task_detatils` WHERE FIND_IN_SET( '1', responsible_user) 将含有1的responsible_user列数据全部搜索出来

  9. Unity&C# Time时间相关

    1.Unity Time类 1/ Time.time 表示从游戏开发到现在的时间,会随着游戏的暂停而停止计算. 2/ Time.timeSinceLevelLoad 表示从当前Scene开始到目前为止 ...

  10. Android系统自带样式(android:theme)

    Theme.Dialog : (图1)Activity显示为对话框模式 Theme.NoTitleBar : (图2)不显示应用程序标题栏 Theme.NoTitleBar.Fullscreen : ...