Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 5473   Accepted: 2379

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 Mrocks (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 ofM 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

输入L,N,M;L表示终点离起点的距离,从起点到终点有N块石头(不包含起点和终点),要求移除M块石头后,使得那时的最短距离尽可能的大,并输出这个距离;
类似于poj3273;
 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int N = ;
int l,n,m;
int rock[N+];
int low,high,mid; bool judge(int mid)
{
int sum = ;
int group = ;
for(int i = ; i <= n+; i++)
{
if(sum + (rock[i]-rock[i-]) <= mid)
{
sum += rock[i]-rock[i-];
group++;
}
else
{
sum = ;
}
}
if(group > m)
return false;
return true;
} int main()
{
scanf("%d %d %d",&l,&n,&m);
rock[] = ;
rock[n+] = l;
low = l;
high = l;
for(int i = ; i <= n+; i++)
{
if(i <= n)
scanf("%d",&rock[i]);
if(low > rock[i]-rock[i-])
low = rock[i]-rock[i-];
}
sort(rock,rock+(n+)); while(low <= high)
{
mid = (low+high)/;
if(!judge(mid))
high = mid-;
else low = mid+;
}
printf("%d\n",low);
return ;
}

River Hopscotch(二分)的更多相关文章

  1. River Hopscotch(二分POJ3258)

    River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9263 Accepted: 3994 Descr ...

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

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

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

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

  4. POJ3258 River Hopscotch —— 二分

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

  5. POJ 3258:River Hopscotch 二分的好想法

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9326   Accepted: 4016 D ...

  6. G - River Hopscotch(二分)

    Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully ...

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

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

  8. poj 3258 River Hopscotch 二分

    /** 大意:给定n个点,删除其中的m个点,其中两点之间距离最小的最大值 思路: 二分最小值的最大值---〉t,若有距离小于t,则可以将前面的节点删除:若节点大于t,则继续往下查看 若删除的节点大于m ...

  9. POJ 3258 River Hopscotch 二分枚举

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

随机推荐

  1. 第三篇:GPU 并行编程的运算架构

    前言 GPU 是如何实现并行的?它实现的方式较之 CPU 的多线程又有什么分别? 本文将做一个较为细致的分析. GPU 并行计算架构 GPU 并行编程的核心在于线程,一个线程就是程序中的一个单一指令流 ...

  2. Driving the Activity Lifecycle

    Before Robolectric 2.2, most tests created Activities by calling constructors directly, (new MyActiv ...

  3. svs 在创建的时候 上传文件夹 bin obj 这些不要提交

    svs  在创建的时候 上传文件夹 bin  obj  这些不要提交  右键-去除版本控制并增加到忽略列表

  4. web前端:js

    内嵌样式<script></script> alert(“123”)弹出对话框 document.write(“test”) 引入方式 <title></ti ...

  5. C#.net时间戳转换

    //long ticks = (DateTime.Parse(DateTime.Now.ToString(CultureInfo.InvariantCulture)).ToUniversalTime( ...

  6. 删除我的电脑中360随身WiFi云U盘的图标

    可通过删除注册表的方法 运行-regedit 找到这个项 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\My ...

  7. 关于ios8斯坦福公开课第二课

    在这个课程中,我们遇到了这样的代码 @IBAction func oprate(sender: UIButton) { let opration = sender.currentTitle! if u ...

  8. VB热点答疑(2016.5.11更新Q4、Q5)

    收录助教君在VB习题课上最常被问到的问题,每周更新,希望对大家有所帮助. Q1.如何让新的文本内容接在原来的内容后面/下一行显示? A1.例如,Label1.text原本的内容是"VB程序设 ...

  9. 解决 dyld: Library not loaded:Reason: image not found

    在使用第三方framework时,直接把framework拖到项目中,运行时报错: dyld: Library not loaded: @rpath/ZipZap.framework/ZipZap R ...

  10. 基于Jquery+Ajax+Json实现分页显示

    1.后台action产生json数据. List blackList = blackService.getBlackInfoList(mobileNum, gatewayid, startDate, ...