1650: [Usaco2006 Dec]River Hopscotch 跳石子

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 721  Solved: 457
[Submit][Status][Discuss]

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

Sample Output

4

二分答案,然后判断是否合法

注意英文题面中0和L也是两个石子,并且这两个石子不可移除

#include<stdio.h>
#include<algorithm>
using namespace std;
int n, m, a[50010];
int Jud(int x)
{int i, sum, temp;temp = 1, sum = 0;for(i=2;i<=n;i++){if(a[i]-a[temp]<x)sum++;elsetemp = i;}if(sum>m)return 0;return 1;
}
int main(void)
{int len, i, l, r, mid;scanf("%d%d%d", &len, &n, &m);a[1] = 0, a[n+2] = len;for(i=2;i<=n+1;i++)scanf("%d", &a[i]);n += 2;sort(a+1, a+n+1);l = 1, r = len;while(l<r){mid = (l+r+1)/2;if(Jud(mid))l = mid;elser = mid-1;}printf("%d\n", l);return 0;
}

bzoj 1650: [Usaco2006 Dec]River Hopscotch 跳石子(二分)相关推荐

  1. 后缀数组2.0--Height数组(bzoj 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式)

    前置技能:后缀数组 height[i]:排名第i的后缀与排名第i-1的后缀的最长公共前缀,也就是sa[i]和sa[i-1]的最长公共前缀 h[i]:以第i个字符为起点的后缀与排名在它前1名的后缀的最长 ...

  2. bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐(暴力DFS)

    1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 774  Solved: 480 ...

  3. River Hopscotch问题(二分)

    又是一个卡了我好久好久好久的二分题 我真的不会二分啊,有没有大佬可以给我讲讲 我就是个憨憨 题目链接River Hopscotch 题目描述: Every year the cows hold an ...

  4. BZOJ 1717 [Usaco2006 Dec]Milk Patterns 产奶的模式(后缀数组)

    [题目链接]http://www.lydsy.com/JudgeOnline/problem.php?id=1717 [题目大意] 求一个最长的串,使得其在母串中出现的次数达到要求 [题解] 二分答案 ...

  5. BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数(数位DP+恶心细节)

    BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数 Time Limit: 5 Sec  Memory Limit: 64 MB Description 正如你所知 ...

  6. 【POJ No. 3258】 跳房子游戏 River Hopscotch

    [POJ No. 3258] 跳房子游戏 River Hopscotch POJ题目地址 [题意] 跳房子游戏指从河中的一块石头跳到另一块石头,这发生在一条又长又直的河流中,从一块石头开始,到另一块石 ...

  7. River Hopscotch

    题目链接:http://poj.org/problem?id=3258 River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total ...

  8. POJ 3258 River Hopscotch 经典二分

    点击打开链接 River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6189   Accepted: ...

  9. 【BZOJ】1649: [Usaco2006 Dec]Cow Roller Coaster(dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1649 又是题解... 设f[i][j]表示费用i长度j得到的最大乐趣 f[i][end[a]]=ma ...

最新文章

  1. python与excel结合-Python与Excel 不得不说的事情
  2. 现在社交APP发展如何?
  3. mysql中给用户添加密码_MySql中添加用户,新建数据库,用户授权,删除用户,修改密码...
  4. JAVA错误日志(part1)--编码GBK的不可映射字符
  5. 在SAP云平台ABAP编程环境上编写第一段ABAP程序
  6. 该省代码的地方要省,反之亦然。
  7. 打磨锤子计算机专业,工大金课 | 在北工大校园里,磨一把“工大锤”
  8. DevExpress控件学习之GridControl的Row拖拽
  9. Oracle 11g 新特性 – HM(Hang Manager)简介
  10. atheros ar9285 wireless network Adaper设备的驱动器正防止机器进入待机状态
  11. 不良事件总结怎么写_不良事件总结
  12. 所谓的进步和提升,就是完成认知升级
  13. nRF 主机扫描过滤器
  14. csgo服务器搭建(linux)
  15. 自问自答学ArrayList,看这篇就够了,详解问答
  16. 明基发布T系列智能商务投影机
  17. 5图片展示_作为一名跨境卖家,产品图片不这样拍还怎么靠“脸”吃饭?
  18. 30_ue4[动画]02_动画蓝图播放蒙太奇和打包
  19. 【数据库视频】报表服务
  20. 中文垂直搜索引擎、行业搜索引擎大全

热门文章

  1. python没基础能自学吗-没学过编程可以自学python吗
  2. 为什么都建议学java而不是python-学java好还是Python好?
  3. python编程案例教程-Python程序设计案例教程
  4. 语音输入常见六大误区 你中招几条?
  5. windows 下使用 MinGW + msys 编译 ffmpeg
  6. android mk subst功能,Android.mk(零)
  7. mysql主从复制超简单_MYSQL 主从复制---简单易学
  8. C# 字典键值对排序 属性的key和value排序
  9. 深入解析oracle电子版,深入解析Oracle数据库
  10. java将数组置零的函数,Java Script 数组内置函数