River Hopscotch

Time Limit: 2000MS Memory Limit: 65536K

Total Submissions: 17740 Accepted: 7414

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.

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


解题心得:

  1. 有n块石头排成一列,每个石头距离原点有一个距离,现在要移走m块石头,问这些牛要跳在(n-m) 块石头上,怎么移走石头让牛每次跳的最短距离最大。输入最短的最大距离。
  2. 看到这个最短距离最大其实也就想到二分了。首先要明白(n-m)块石头,牛要跳n-m+2次(起点和终点没有石头但是也要跳)。然后二分检查。

#include <algorithm>
#include <stdio.h>
#include <cstring>
using namespace std;
const int maxn = 5e5+100;
int pos[maxn],n,m,l,tot; void init() {
pos[0] = 0;
for(int i=1;i<=n;i++)
scanf("%d",&pos[i]);
pos[n+1] = l;
n += 2;
sort(pos,pos+n);
tot = n-m;
} bool checke(int len){
int cnt = 1,now = pos[0];
for(int i=1;i<n;i++) {
if(pos[i] - now >= len) {
cnt++;
now = pos[i];
}
}
if(cnt >= tot)
return true;
return false;
} int binary_search() {
int l = 0,r = 1e9+100;
while(r - l > 1) {
int mid = (l + r) / 2;
if(checke(mid))
l = mid;
else
r = mid;
}
return l;
} int main() {
while(scanf("%d%d%d",&l,&n,&m) != EOF) {
init();
int ans = binary_search();
printf("%d\n",ans);
}
return 0;
}

POJ:3258-River Hopscotch的更多相关文章

  1. 二分搜索 POJ 3258 River Hopscotch

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

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

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

  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. poj 3258 River Hopscotch(二分+贪心)

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

  7. POJ 3258 River Hopscotch 二分枚举

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

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

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

  9. poj 3258 River Hopscotch 题解

    [题意] 牛要到河对岸,在与河岸垂直的一条线上,河中有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. XHML教会我的一些东西-3

    在寒假期间,隔几天就同学聚会,每天都是起床困难户.每天都想着要完成任务,要学习新的东西.但是总是被自己惰性占为上风.感觉自己很没用,但是又继续堕落.真的不能理解自己.呵呵.... 在放假一段时间之后, ...

  2. 移动webApp - 1像素实现(点5像素的秘密)

    在移动web项目中,经常会实现以下1像素的边框 移动web设计中,在retina显示屏下网页会由1px会被渲染为2px,那么视觉稿中1px的线条还原成网页需要css定义为0.5px 但是正当我们去用0 ...

  3. 解析Excel文件 Apache POI框架使用

    本文整理了,使用Apache POI 框架解析.读取Excel文件,过程中,程序代码出现的一些问题,并解决 1..xls 和 .xlsx 我们知道Excel文档,在Windows下,分为Excel20 ...

  4. centos部署vue项目

    参考链接 nodejs服务器部署教程二,把vue项目部署到线上 打包 #在本地使用以下命令,打包 npm run build #打包之后本地会出现dist文件夹.将dist文件夹以及package.j ...

  5. iOS自动化打包发布(fastlane)

    一.FastLane介绍 1.1 FastLane是什么? FastLane是一种配置iOS和Android自动化Beta部署和发布的最简单的方法之一.它可以简化一些乏味.单调.重复的工作,像截图.代 ...

  6. vi使用命令

    二.移动光标类命令 h :光标左移一个字符 l :光标右移一个字符 space:光标右移一个字符 Backspace:光标左移一个字符 k或Ctrl+p:光标上移一行 j或Ctrl+n :光标下移一行 ...

  7. 如何在CRM WebClient UI里使用HANA Live Report

    1. 使用业务角色ANALYTICSPRO登录SAP CRM WebClient UI: 点击新建按钮创建一个新的HANA live report: 类型选择SHL: 弹出窗口,维护report的名称 ...

  8. Aizu The Maximum Number of Customers

    http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_5_A The Maximum Number of Customers Ide ...

  9. Selenium入门17 selenium IDE安装及使用

    selenium IDE是firefox浏览器的一个插件,支持脚本的录制回放,关键字驱动的.界面跟robotframework很像. 实际测试中不用录制回放,不过初学者拿来看看元素是如何定位的还是有用 ...

  10. PHP编译安装时常见错误及解决办法,大全

    1.   configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution ...