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).
 
思路
1. 二分法
 
代码
Source Code

Problem:         User: blazing
Memory: 424K Time: 157MS
Language: C++ Result: Accepted
Source Code
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
const int MAXN = ;
int L, N, M;
int rocks[MAXN]; int binarySearch(int low, int high) {
while( low <= high ) {
int count = , lastPos = ;
int mid = ( low + high ) >> ;
//cout << "mid : " << mid << endl;
for( int i = ; i <= N+; i ++ ) {
if( rocks[i] - rocks[lastPos] < mid ) {
// move one rock to extend the distance
count += ;
}else {
lastPos = i;
}
} if (count > M)
high = mid - ;
else
low = mid + ;
}
return high;
} int main() {
//freopen("E:\\Copy\\ACM\\poj\\3258_v2\\in.txt", "r", stdin);
while( cin >> L >> N >> M ) {
int low = 0x3FFFFFFF;
memset( rocks, , sizeof(rocks));
for( int i = ; i <= N; i ++ ) {
scanf("%d", &rocks[i]);
}
rocks[] = , rocks[N+] = L;
sort( rocks, rocks+N+); for(int i = ; i <= N+; i++) {
low = min ( low, rocks[i]-rocks[i-] );
} cout << binarySearch( low, L ) << endl;
}
return ;
}

POJ 3258 River Hopscotch(二分法搜索)的更多相关文章

  1. POJ 3258 River Hopscotch (二分法)

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

  2. 二分搜索 POJ 3258 River Hopscotch

    题目传送门 /* 二分:搜索距离,判断时距离小于d的石头拿掉 */ #include <cstdio> #include <algorithm> #include <cs ...

  3. POJ 3258 River Hopscotch

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11031   Accepted: 4737 ...

  4. POJ 3258 River Hopscotch (binarysearch)

    River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5193 Accepted: 2260 Descr ...

  5. POJ 3258 River Hopscotch(二分答案)

    River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 21939 Accepted: 9081 Desc ...

  6. [ACM] POJ 3258 River Hopscotch (二分,最大化最小值)

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6697   Accepted: 2893 D ...

  7. poj 3258 River Hopscotch 题解

    [题意] 牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离, 现在去掉M块石头,要求去掉M块石头后,剩下的石头之间以及石头与河岸的最小距离的最大值 ...

  8. poj 3258 River Hopscotch(二分+贪心)

    题目:http://poj.org/problem?id=3258 题意: 一条河长度为 L,河的起点(Start)和终点(End)分别有2块石头,S到E的距离就是L. 河中有n块石头,每块石头到S都 ...

  9. POJ 3258 River Hopscotch 二分枚举

    题目:http://poj.org/problem?id=3258 又A一道,睡觉去了.. #include <stdio.h> #include <algorithm> ]; ...

随机推荐

  1. JS事件对象,筋斗云导航练习,跟随鼠标练习,放大镜练习,进度条练习

    JS事件对象,筋斗云导航练习,跟随鼠标练习,放大镜练习,进度条练习 btn.onclick = function(event) { 语句 } 其中event就是事件对象,在这个方法中指向的对象是onc ...

  2. Spring Cloud Sleuth Zipkin - (2)

    在上一节<spring-cloud-sleuth+zipkin追踪服务实现(一)>中,我们使用zipkin-server.provider.consumer三个程序实现了使用http方式进 ...

  3. Paxos算法细节详解(一)

    Paxos分析 最近研究paxos算法,看了许多相关的文章,概念还是很模糊,觉得还是没有掌握paxos算法的精髓,所以花了3天时间分析了libpaxos3的所有代码,此代码可以从https://bit ...

  4. 给Libgdx的ShapeRenderer开启抗锯齿

    http://blog.rpsg-team.com/?p=134 ——————————————————————————————————————————————————————————————————— ...

  5. PHP产生随机数

    PHP生成随机字符串包括大小写字母 PHP生成随机字符串包括大小写字母,这里介绍两种方法: 第一种:利用字符串函数操作 ? <?php     /**      *@blog <www.p ...

  6. USB2.0相关应用笔记集锦

    在AN65209中 有一些应用笔记集锦,希望对大家有用.当然AN65209这篇应用笔记很重要,希望大家一定要看!!!一定要看!!!!

  7. e859. 将键盘事件和字符串对应

    The KeyStroke.toString() method does not return a string that can be parsed by KeyStroke.getKeyStrok ...

  8. TPshop隐藏index.php

    有些朋友提到关于TPshop 隐藏index.php 一问题, 可以修改 Application\Common\Conf\config.php 文件代码 'common', 'AUTH_CODE' = ...

  9. 嵌入式开发之zynq驱动—— zynq ps pl ddr 内存地址空间映射

    http://www.wiki.xilinx.com/Zynq-7000+AP+SoC+-+32+Bit+DDR+Access+with+ECC+Tech+Tip http://patchwork.o ...

  10. Python——eventlet

    eventlet语境下的“绿色线程”普通线程之间的区别: 1. 绿色线程几乎没有开销,不用像保留普通线程一样保留“绿色线程”,每一个网络连接对应至少一个“绿色线程”: 2. 绿色线程需要人为的设置使其 ...