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. Part2-HttpClient官方教程-Chapter2-连接管理

    2.1 连接持久性 建立从一个主机到另一个主机的连接的过程相当复杂,并且涉及两个端点之间的多个分组交换,这可能相当耗时.连接握手的开销可能很大,特别是对于小型的HTTP消息. 如果可以重新使用开放连接 ...

  2. Centos7编译安装Xen环境(vtpm)

    编译xen环境(http://www.lvtao.net/server/574.html#comment-1882): yum update yum groupinstall "Develo ...

  3. GCC在C语言中内嵌汇编 asm __volatile__ 【转】

    转自:http://blog.csdn.net/pbymw8iwm/article/details/8227839 在内嵌汇编中,可以将C语言表达式指定为汇编指令的操作数,而且不用去管如何将C语言表达 ...

  4. 測試 battery capacity curve 的負載

    昨天有同事問說, 他要測試 battery capacity curve, 並且負載要使用 33mA, 於是我想到有一個 apk 名稱為 快速放電 (最下方),可以控制 cpu 的 load, 他試了 ...

  5. 64_m2

    mimetic-devel-0.9.8-7.fc26.i686.rpm 12-Feb-2017 05:40 288474 mimetic-devel-0.9.8-7.fc26.x86_64.rpm 1 ...

  6. 刷新SqlServer数据库中所有的视图

    ALTER PROCEDURE sp_refallview AS --刷新所有视图 DECLARE @ViewName VARCHAR(MAX); DECLARE @i INT; ; DECLARE ...

  7. aspxpivotgrid排序

    protected virtual void SetSortBySummary() { foreach (PivotGridField field in grid.Fields) { if (fiel ...

  8. 大小端 Big-Endian 与 Little-Endian

    应该说没做底层开发(硬件或驱动)的人很可能不会彻底理解大小端的概念,大小端不是简单的一句“大端在前”还是“小端在前”能够概括的问题.在cpu, 内存, 操作系统, 编译选项, 文件,网络传输中均有大小 ...

  9. 【python】pymongo中正则查询时的转义问题

    在查询mongo时用到了正则查询 设字符串为   str = '/ab/cd.ef?g=' 直接用正则查询没有匹配. collection.find({"re":{'$regex' ...

  10. memcached安装+绑定访问ip

    安装: 1.由于memcached是基于libevent的,需要安装libevent,libevent-devel $yum -y install libevent libevent-devel 2. ...