bzoj 1650: [Usaco2006 Dec]River Hopscotch 跳石子
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
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
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 跳石子的更多相关文章
- BZOJ 1650 [Usaco2006 Dec]River Hopscotch 跳石子:二分
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1650 题意: 数轴上有n个石子,第i个石头的坐标为Di,现在要从0跳到L,每次条都从一个石 ...
- bzoj 1650: [Usaco2006 Dec]River Hopscotch 跳石子【贪心+二分】
脑子一抽写了个堆,发现不对才想起来最值用二分 然后判断的时候贪心的把不合mid的区间打通,看打通次数是否小于等于m即可 #include<iostream> #include<cst ...
- 【BZOJ】1650: [Usaco2006 Dec]River Hopscotch 跳石子(二分+贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1650 看到数据和最小最大时一眼就是二分... 但是仔细想想好像判断时不能贪心? 然后看题解还真是贪心 ...
- bzoj1650 [Usaco2006 Dec]River Hopscotch 跳石子
Description Every year the cows hold an event featuring a peculiar version of hopscotch that involve ...
- BZOJ 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 [后缀数组]
1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1017 Solved: ...
- Bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 深搜,bitset
1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 554 Solved: 346[ ...
- BZOJ 1649: [Usaco2006 Dec]Cow Roller Coaster( dp )
有点类似背包 , 就是那样子搞... --------------------------------------------------------------------------------- ...
- BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐( dfs )
直接从每个奶牛所在的farm dfs , 然后算一下.. ----------------------------------------------------------------------- ...
- BZOJ 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式( 二分答案 + 后缀数组 )
二分答案m, 后缀数组求出height数组后分组来判断. ------------------------------------------------------------ #include&l ...
随机推荐
- epoll内核源码分析
转载:https://www.nowcoder.com/discuss/26226?type=0&order=0&pos=27&page=1 /* * fs/eventpo ...
- STM32接口FSMC/FMC难点详解
STM32接口FSMC/FMC难点详解 转载 http://blog.sina.com.cn/s/blog_808bca130102x94k.html STM32F767的FMC将外部存储器划分为 ...
- 《LINUX3.0内核源代码分析》第二章:中断和异常 【转】
转自:http://blog.chinaunix.net/uid-25845340-id-2982887.html 摘要:第二章主要讲述linux如何处理ARM cortex A9多核处理器的中断.异 ...
- 2015多校第7场 HDU 5379 Mahjong tree 构造,DFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5379 题意:一颗n个节点n-1条边的树,现在要给每个节点标号(1~n),要求:(1)每一层的兄弟节点的 ...
- MyEclipse/Eclipse安装插件的几种方式
众所周知MyEclipse是一个很强大的Java IDE,而且它有许多开源免费又好用的插件,这些插件给我们开发过程中带来了许多方便.插件具有针对性,例如,你如果做安卓开发,可能需要一个ADT(Andr ...
- JavaScript中数组对象详解
Array对象即数组对象用于在单个变量中存储多个值,JS的数组是弱类型的,所以允许数组中含有不同类型的元素,数组元素甚至可以是对象或者其他数组. 创建数组的语法 1.Array构造器 1.var li ...
- 如何在本地用vs调试微信接口
这段时间在研究微信,看了网上很多都是把项目发布之后在服务器上调试,可以我想可以直接在vs上面设置断点调试 刚开始才用 http://www.cnblogs.com/hanzhaoxin/p/45186 ...
- 关于级联查询,mybatis
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE mapper PUBLIC "-// ...
- C/C++——[01] 程序的基本框架
我们以HelloWorld这个简单程序为例,该程序在终端打印一行文本: Hello World! 代码如下: #include <stdio.h> int main(){ printf(& ...
- DNS解析原理与Bind部署DNS服务
DNS是什么? DNS(Domain Name System,域名系统)是互联网上最核心的带层级的分布式系统,它负责把域名转换为IP地址.反查IP到域名的反向解析以及宣告邮件路由等信息,使得基于域名提 ...