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. Java基础知识强化之集合框架笔记40:Set集合之HashSet存储自定义对象并遍历

    1. HashSet存储自定义对象并遍历 2. 代码示例: (1)Student类,如下: package cn.itcast_02; /** * @author Administrator * */ ...

  2. Objective-C:KVC

    1 概述 1.1 访问方法 Key-value coding(KVC)是一种间接访问对象属性的机制,类似键值对,通过名字(或键)可以直接获得对象的属性值.事实上,key-value coding定义了 ...

  3. Fileupload控件导致500错误

    问题: 今天遇到一个问题,用Fileupload控件上传Excel文件,用一个button控件调用“FileUpload1.SaveAs”方法,点击按钮后出现服务器500错误.如下图: 解决方法: 在 ...

  4. Registry 类

    提供表示 Windows 注册表中的根项的 RegistryKey 对象,并提供访问项/值对的 static 方法. 继承层次结构 System.Object   Microsoft.Win32.Re ...

  5. Android中dip,dp,sp,pt和px的区别

    dip: device independent pixels(设备独立像素). 不同设备有不同的显示效果,这个和设备硬件有关,一般我们为了支持WVGA.HVGA和QVGA 推荐使用这个,不依赖像素. ...

  6. Echarts使用随笔(1)-Echarts中markPoint的使用(静态、动态)-effect

    先看一段关于初始化Echart   js的使用  myChart = echarts.init(document.getElementById('mainChart'));         var o ...

  7. C# 面向对象编程的继承性-多继承

    多继承 如果要使用多继承,需要使用接口,因为C#中的类只支持单继承,而接口支持多继承,实现多继承时,继承的多个接口中间用逗号(,)隔开. 说明: 实现多继承时,继承的可以是多个接口,也可以是一个类及多 ...

  8. helloServlet

    创建第一个web程序 用myeclipse创建一个web项目,继而创建一个servlet 自动帮助你创建了一个web.xml文件 <servlet>....<servlet>指 ...

  9. 【POJ2887】【块状链表】Big String

    Description You are given a string and supposed to do some string manipulations. Input The first lin ...

  10. Oracle IN 传递字符串参数查询失效

    在写存储过程中有如下代码: FOR a IN ( SELECT a.svo_no,a.AUDIT_NO,a.order_id FROM TT_PI_MODEL_REL a ) LOOP SELECT ...