River Hopscotch
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 5961   Accepted: 2579

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 ≤ MN).

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: 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

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

Source

二分搜索

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream> using namespace std; #define maxn 50005 int L,n,m;
int dis[maxn]; bool judge(int x) {
int now = ; int t = m;
for(int i = ; i <= n; i++) {
if(dis[i] - now < x) {
--t;
} else {
now = dis[i];
}
} if(L - now < x) {
--t;
} return t >= ;
} void solve() {
int r = L,l = ; while(l < r) {
int mid = (l + r + ) >> ;
if(judge(mid)) {
l = mid;
} else {
r = mid - ;
}
} printf("%d\n",l);
} int main() {
// freopen("sw.in","r",stdin); scanf("%d%d%d",&L,&n,&m);
for(int i = ; i <= n; i++) {
scanf("%d",&dis[i]);
} sort(dis + ,dis + n + ); solve(); return ;
}

POJ 3258的更多相关文章

  1. poj 3258 River Hopscotch 题解

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

  2. 二分搜索 POJ 3258 River Hopscotch

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

  3. E - River Hopscotch POJ - 3258(二分)

    E - River Hopscotch POJ - 3258 Every year the cows hold an event featuring a peculiar version of hop ...

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

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

  5. POJ 3258 River Hopscotch 二分枚举

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

  6. POJ 3258(二分求最大化最小值)

    题目链接:http://poj.org/problem?id=3258 题目大意是求删除哪M块石头之后似的石头之间的最短距离最大. 这道题目感觉大致代码写起来不算困难,难点在于边界处理上.我思考边界思 ...

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

    嗯... 题目链接:http://poj.org/problem?id=3258 一道很典型的二分答案的题目,和跳石头太像了!! 这道题的题目很显然,求最小中的最大值,注意这道题石头的位置不是从小到大 ...

  8. poj 3258 River Hopscotch 【二分】

    题目真是不好读,大意例如以下(知道题意就非常好解了) 大致题意: 一条河长度为 L,河的起点(Start)和终点(End)分别有2块石头,S到E的距离就是L. 河中有n块石头,每块石头到S都有唯一的距 ...

  9. poj 3258 3273

    poj3258 题目  (最大化最小值)(最小值最大化) 题意:牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离,现在去掉M块石头,要求去掉M块石 ...

  10. POJ 3258 River Hopscotch(二分法搜索)

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

随机推荐

  1. Map排序(按key/按value)

    package com.abc.test; import java.util.ArrayList; import java.util.Arrays; import java.util.Collecti ...

  2. Android实现Http协议案例

    在Android开发中,使用Http协议实现网络之间的通信是随处可见的,使用http方式主要采用2中请求方式即get和post两种方式. 一.使用get方式: HttpGet httpGet = ne ...

  3. 修改 timezone

    1.通过命令修改 1.Set Time, Date Timezone in Linux from Command Line or Gnome | Use ntp 2.Use TZ database 3 ...

  4. python 中range与xrange的区别

    先来看看range与xrange的用法介绍 help(range)Help on built-in function range in module __builtin__: range(...) r ...

  5. 合并大量txt文件的内容

    首先熟悉一个dos命令 显示文件内容命令——type命令 1.格式:type [盘符:] [路径] 文件名 2.类型:内部命令 3.功能:把指定的文件内容在屏幕上显示或打印机输出,它常用作查阅和显示文 ...

  6. linux系统目录架构

    /bin目录:可执行的二进制文件,shell命令(就是我们说的命令:cp ls ...),所有用户都有权执行. /boot目录:引导目录,整个操作系统启动所需的所有文件都在该目录下,其中最主要的就是v ...

  7. IntelliJ IDEA+Tomcat+Nginx运行git项目

    1.克隆Git项目到本地 (1)设置Git工具路径:file>settings>Version Control>Git (2)设置GitHub账户:file>settings& ...

  8. JQ中的html()、text()、val()的用法

    <input type="text" val=""> 用val(); <sapn>你好</sapn>  用text() &l ...

  9. 用PHP判断客户端是否是手机

    <?php function isMobile(){ $useragent = isset($_SERVER['HTTP_USER_AGENT'])? $_SERVER['HTTP_USER_A ...

  10. delphi下,不错的多语言翻译组件

    http://yktoo.com/en/software/dklangTraned http://sourceforge.net/projects/dklang/