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

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

Source

——————————————————————————————————

题目的意思是给出n个数,取走m个要求两两之间(以及和岸的)最小值最大是多少?

思路:二分最小距离+验证

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define inf 0x3f3f3f3f
#define LL long long int a[100005];
int n,m,mx;
bool ok(int x)
{
int cnt=0;
int sum=0;
for(int i=1;i<n;i++)
{
sum+=a[i]-a[i-1];
if(sum<x)
cnt++;
else
sum=0;
}
if(cnt<=m)
return 1;
return 0; } int main()
{ while(~scanf("%d%d%d",&mx,&n,&m))
{
a[0]=0,a[n+1]=mx;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
n+=2;
sort(a,a+n);
int l=0,r=1000000000;
int ans;
while(l<=r)
{
int mid=(l+r)/2;
if(ok(mid))
{
l=mid+1;
ans=mid;
}
else
{
r=mid-1;
}
}
printf("%d\n",ans);
}
return 0;
}

POJ3258 River Hopscotch 2017-05-11 17:58 36人阅读 评论(0) 收藏的更多相关文章

  1. hash值的计算与转换 分类: ACM TYPE 2015-05-07 17:49 36人阅读 评论(0) 收藏

    #include <bits/stdc++.h> using namespace std; const int MAXN = 100; const int X = 3; long long ...

  2. Java中的日期操作 分类: B1_JAVA 2015-02-16 17:55 6014人阅读 评论(0) 收藏

    在日志中常用的记录当前时间及程序运行时长的方法: public void inject(Path urlDir) throws Exception { SimpleDateFormat sdf = n ...

  3. strace使用详解(转) 分类: shell ubuntu 2014-11-27 17:48 134人阅读 评论(0) 收藏

    (一) strace 命令    用途:打印 STREAMS 跟踪消息. 语法:strace [ mid sid level ] ... 描述:没有参数的 strace 命令将所有的驱动程序和模块中的 ...

  4. hdu 1057 (simulation, use sentinel to avoid boudary testing, use swap trick to avoid extra copy.) 分类: hdoj 2015-06-19 11:58 25人阅读 评论(0) 收藏

    use sentinel to avoid boudary testing, use swap trick to avoid extra copy. original version #include ...

  5. Design T-Shirt 分类: HDU 2015-06-26 11:58 7人阅读 评论(0) 收藏

    Design T-Shirt Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  6. UIAlertController高级之嵌入其他控件 分类: ios技术 2015-02-02 11:58 96人阅读 评论(0) 收藏

    在编码过程中,我们经常遇到需要这样一个效果,就是弹出框的嵌套; 举个最简单的例子,比如你要选择时间,必然需要一个时间选择器DatePicker.但是这个选择器又是在你点击某按钮时弹出,弹出方式最常见的 ...

  7. Codeforces735B Urbanization 2016-12-13 11:58 114人阅读 评论(0) 收藏

    B. Urbanization time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  8. StatusStrip 分类: C# 2015-07-23 11:58 2人阅读 评论(0) 收藏

    通过StatusStrip显示窗体状态栏 同时将状态栏分成三部分 居左边显示相关文字信息 中间空白显示 居右边显示时间信息 1.创建窗体及添加StatusStrip   默认StatusStrip名称 ...

  9. APP被苹果APPStore拒绝的各种原因 分类: ios相关 app相关 2015-06-25 17:27 200人阅读 评论(0) 收藏

    APP被苹果APPStore拒绝的各种原因 1.程序有重大bug,程序不能启动,或者中途退出. 2.绕过苹果的付费渠道,我们之前游戏里的用兑换码兑换金币. 3.游戏里有实物奖励的话,一定要说清楚,奖励 ...

随机推荐

  1. Haskell语言学习笔记(29)CPS

    CPS (Continuation Passing Style) CPS(延续传递风格)是指函数不把处理结果作为返回值返回而是把处理结果传递给下一个函数的编码风格. 与此相对,函数把处理结果作为返回值 ...

  2. break、continue、pass介绍

    break.continue.pass介绍 break:跳出当前循环 continue:跳出本次循环,进行下一次循环 pass:什么也不做,占位.

  3. oozie错误:javax.servlet.jsp.el.ELException: variable [***] cannot be resolved

    完整错误: javax.servlet.jsp.el.ELException: variable [compute] cannot be resolved at org.apache.oozie.ut ...

  4. HTML的实际演练1

    1.HTML介绍 一个网站的建立都是HTML的,例如大家可以打开F12就可以看到浏览器的一个开发者模式,就可以看到网页的源代码了: 当然这网页他有很多的标签编写组成的,有的显示文字,段落,有的是个超链 ...

  5. java基础五 [数字与静态](阅读Head First Java记录)

    本章主要讲了静态变量.静态方法,final关键词.以及介绍了怎么对数字和日期进行格式化输出.这里对这些内容进行了整理.本章还介绍了java.util.Date和java.util.Calendar来操 ...

  6. luoguP3367 [模板]并查集

    题目链接:https://www.luogu.org/problemnew/show/P3367 思路: 今天学了新算法——并查集,本题是简单的并查集题的模板. 核心思想是“递归+压缩路径”. 并查集 ...

  7. sqserver2008触发器

    @参考博文 先上代码 先建个表用于测试 CREATE TRIGGER INSERT_forbidden on s after INSERT AS BEGIN RAISERROR(,) ROLLBACK ...

  8. ROS Learning-009 beginner_Tutorials ROS服务 和 ROS参数

    ROS Indigo beginner_Tutorials-08 ROS服务 和 ROS参数 我使用的虚拟机软件:VMware Workstation 11 使用的Ubuntu系统:Ubuntu 14 ...

  9. (一)ROS的安装与环境配置

    1.设置教程 1.1 打开system setting(系统设置)->Software&Updates(软件与更新) 1.2点击上方Other software(其他软件),点击左下角a ...

  10. php单点登陆简单实现 (iframe方式)

    有四个网站分别为: www.a.com www.b.com www.c.com www.sso.com 需求是如果我们在sso登陆后,其他网站也会显示登陆中,不需要重复登陆,退出时,其他网站也会失效. ...