River Hopscotch
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 11155   Accepted: 4785

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 distanceDi 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
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN=;
int l,n,m;
int x[MAXN];
bool test(int d)
{
int cnt=;
int last=;
for(int i=;i<n;i++)
{
if(x[i]-last<d)
{
cnt++;
continue;
}
last=x[i];
}
if(l-last<d) return false;
return cnt<=m;
}
int main()
{
while(scanf("%d%d%d",&l,&n,&m)!=EOF)
{
for(int i=;i<n;i++)
{
scanf("%d",&x[i]);
}
sort(x,x+n);
int l=,r=0x3f3f3f3f;
while(r-l>)
{
int mid=(l+r)>>;
if(test(mid))
{
l=mid;
}
else
{
r=mid;
}
}
printf("%d\n",l);
}
return ;
}

POJ3258(最大化最小值)的更多相关文章

  1. POJ_2456_Agressive_cows_(二分,最大化最小值)

    描述 http://poj.org/problem?id=2456 有n个小屋,线性排列在不同位置,m头牛,每头牛占据一个小屋,求最近的两头牛之间距离的最大值. Aggressive cows Tim ...

  2. POJ3285 River Hopscotch(最大化最小值之二分查找)

    POJ3285 River Hopscotch 此题是大白P142页(即POJ2456)的一个变形题,典型的最大化最小值问题. C(x)表示要求的最小距离为X时,此时需要删除的石子.二分枚举X,直到找 ...

  3. poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分

    poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分 题目链接: nyoj : http://acm.nyist.net/JudgeOnline/ ...

  4. hihocoder 二分·二分答案【二分搜索,最大化最小值】 (bfs)

    题目 这道题做了几个小时了都没有做出来,首先是题意搞了半天都没有弄懂,难道真的是因为我不打游戏所以连题都读不懂了? 反正今天是弄不懂了,过几天再来看看... 题意:一个人从1点出发到T点去打boss, ...

  5. codeforce 1070 E Getting Deals Done(二分求最大化最小值)

    Polycarp has a lot of work to do. Recently he has learned a new time management rule: "if a tas ...

  6. POJ2456(最大化最小值)

    Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10728   Accepted: 5288 ...

  7. 二分法的应用:最大化最小值 POJ2456 Aggressive cows

    /* 二分法的应用:最大化最小值 POJ2456 Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: ...

  8. POJ3258 River Hopscotch(二分最大化最小值)

    题目链接:http://poj.org/problem?id=3258 题意:给n个石头,起点和终点也是两个石头,去掉这石头中的m个,使得石头间距的最小值最大. 思路:二分石头间的最短距离,每次贪心地 ...

  9. poj3258 二分 最小值最大化问题

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10842   Accepted: 4654 ...

随机推荐

  1. 三、golang时间、流程控、函数

    一.本篇内容 1.string和strconv使用 2.go中的时间和日期类型 3.流程控制 4.函数讲解 二.string和strconv使用 1.  string.HasPrefix(s trin ...

  2. linux下安装LAMP环境,也就是PHP+linux的开发运行环境(centos7)

    注:整理至http://blog.51cto.com/afterdawn/1923139 LAMP(linux.apache.mysql.php),是四个套件的合成,简单讲就是要把php运行在linu ...

  3. cocos2dx打飞机项目笔记三:HeroLayer类和坐标系

    HeroLayer类主要是处理hero的一些相关东西,以及调用bulletLayer的一些方法,因为子弹是附属于hero的~~ HeroLayer 类的成员如下: class HeroLayer : ...

  4. .NET CORE 动态调用泛型方法

    using System; using System.Reflection; namespace DynamicCall { class Program { static void Main(stri ...

  5. nginx根据项目名实现内网地址转发

    nginx根据访问的项目名进行内网地址转发 以下是nginx的配置信息: server { listen 8081; server_name localhost; #charset koi8-r; # ...

  6. Spark常用算子-value数据类型的算子

    package com.test; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; im ...

  7. MySQL数据copy

    摘自http://database.51cto.com/art/201011/234776.htm 1. 下面这个语句会拷贝表结构到新表newadmin中. (不会拷贝表中的数据) CREATE TA ...

  8. 机器学习三剑客之Matplotlib

      matplotlib Matplotlib 是Python 2D绘图领域的基础套件,它让使用者将数据图形化,并提供多样化的输出格式.这里将会以四个小案例探索Matplotlib的常见用法 绘制折线 ...

  9. javascript删除JSON元素

    首先要搞清JSON的数据格式,我这里所说的JSON都是指javascript中的. JSON数据是由对象和数组数据结构组成,我们只要学会javascript中对对象和数组的删除方法即可对JSON项进行 ...

  10. dom 兼容性问题 2 offset

        offsetParent : 离当前节点最近的具有定位属性的祖先节点. 如果所有祖先节点都没有定位属性: 对于一个有定位属性的元素: ie6.7 : offsetParent 是 html 节 ...