1650: [Usaco2006 Dec]River Hopscotch 跳石子

Time Limit: 5 Sec  Memory Limit: 64 MB

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

数轴上有n个石子,第i个石头的坐标为Di,现在要从0跳到L,每次条都从一个石子跳到相邻的下一个石子。现在FJ允许你移走M个石子,问移走这M个石子后,相邻两个石子距离的最小值的最大值是多少。

Input

* Line 1: Three space-separated integers: L, N, 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

5 rocks at distances 2, 11, 14, 17, and 21. Starting rock at position
0, finishing rock at position 25.

Sample Output

4

HINT

#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,ll,d[],l=,r;
bool f(int a)
{
int k=,ji=;
for(int i=;i<=n;i++) d[i]-ji<a?k++:ji=d[i];
return k<=m?:;
}
int main()
{
scanf("%d%d%d",&ll,&n,&m);
for(int i=;i<n;i++) scanf("%d",&d[i]);
sort(d,d+n);
d[n]=r=ll;
while(l<r)
{
int mid=(l+r+)>>;
f(mid)?l=mid:r=mid-;
}
printf("%d\n",l);
}

移除之前,最短距离在位置2的石头和起点之间;移除位置2和位置14两个石头后,最短距离变成17和21或21和25之间的4.

bzoj 1650: [Usaco2006 Dec]River Hopscotch 跳石子的更多相关文章

  1. BZOJ 1650 [Usaco2006 Dec]River Hopscotch 跳石子:二分

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1650 题意: 数轴上有n个石子,第i个石头的坐标为Di,现在要从0跳到L,每次条都从一个石 ...

  2. bzoj 1650: [Usaco2006 Dec]River Hopscotch 跳石子【贪心+二分】

    脑子一抽写了个堆,发现不对才想起来最值用二分 然后判断的时候贪心的把不合mid的区间打通,看打通次数是否小于等于m即可 #include<iostream> #include<cst ...

  3. 【BZOJ】1650: [Usaco2006 Dec]River Hopscotch 跳石子(二分+贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1650 看到数据和最小最大时一眼就是二分... 但是仔细想想好像判断时不能贪心? 然后看题解还真是贪心 ...

  4. bzoj1650 [Usaco2006 Dec]River Hopscotch 跳石子

    Description Every year the cows hold an event featuring a peculiar version of hopscotch that involve ...

  5. BZOJ 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 [后缀数组]

    1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1017  Solved: ...

  6. Bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 深搜,bitset

    1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 554  Solved: 346[ ...

  7. BZOJ 1649: [Usaco2006 Dec]Cow Roller Coaster( dp )

    有点类似背包 , 就是那样子搞... --------------------------------------------------------------------------------- ...

  8. BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐( dfs )

    直接从每个奶牛所在的farm dfs , 然后算一下.. ----------------------------------------------------------------------- ...

  9. BZOJ 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式( 二分答案 + 后缀数组 )

    二分答案m, 后缀数组求出height数组后分组来判断. ------------------------------------------------------------ #include&l ...

随机推荐

  1. 浅谈JobExecutionContext与JobDataMap

    1.JobExecutionContext简介 (1)当Scheduler调用一个Job,就会将JobExecutionContext传递给job的execute方法 quartz无法调用job的有参 ...

  2. 【Eclipse】Eclipse中修改项目的映射名称与端口

    1.正常部署(映射的名字为项目名字,端口为8080)

  3. Linux进程调度与源码分析(一)——简介

    本系列文章主要是近期针对Linux进程调度源码进行阅读与分析后的经验总结,分析过程中可能结合部分Linux网络编程的相关知识以便于理解,加深对Linux进程调度的理解和知识分享. 本系列文章主要结合L ...

  4. 【玲珑杯Round17】xjb总结

    zcy真是垃圾,啥都不会的那种. 菜的不行. 这场手速上了三题,然后各种E被卡…… 日个吗居然E不开栈,傻逼吧 有毒吧 来看题: A.sqc给的我的神奇公式,gtmd居然能A? #include< ...

  5. [How to]简单易用的拷贝Mac文件路径方法

    效果: 在你想拷贝路径的文件夹或者文件上右键会出现 copy path 选项! 实现: 1.打开finder的的Automator组件 2.选择[服务]选项,点击[选取]按钮 3.搜索操作项目中[拷贝 ...

  6. java 查看运行时某个类文件所在jar的位置

    在一些大型项目中,项目所依赖的库可能比较到,有时候也会出现库冲突的情况,曾经遇到过一种情况:一个第三方云存储提供了一个sdk,这个sdk本身依赖httpclient相关的包,然而对方却把httpcli ...

  7. 如何生成[0,maxval]范围内m个随机整数的无重复的有序序列

    在这里我们将待生成的数据结构称为IntSet,接口定义如下: class IntSetImp { public: IntSetImp(int maxelements,int maxval); void ...

  8. LeetCode212. Word Search II

    https://leetcode.com/problems/word-search-ii/description/ Given a 2D board and a list of words from ...

  9. python类的使用与多文件组织

    多文件的组织 跨目录级导入模块 from ..xxfile import xxmodule #从上级目录中的xxfile中导入xxmodule import xxsub_dir.xxfile #从xx ...

  10. POJ 1845 Sumdiv (整数唯一分解定理)

    题目链接 Sumdiv Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 25841   Accepted: 6382 Desc ...