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. JAVA使用Freemarker生成静态文件中文乱码

    1.指定Configuration编码 Configuration freemarkerCfg = new Configuration(); freemarkerCfg.setEncoding(Loc ...

  2. HBase学习2(HBase shell)

    HBase 常用命令 查看当前用户:whoami 创建表:create '表名', '列族名1','列族名2','列族名N' 查看所有表:list 描述表: describe '表名' 判断表存在: ...

  3. json对象与字符串互转方法

    字符串转json对象: var data = eval( '(' + str + ')' ); json对象转字符串: var jsonStr = JSON.stringify( obj );

  4. Qt qobject_cast用法 向下转型

    函数原型: T qobject_cast ( QObject * object ) 本方法返回object向下的转型T,如果转型不成功则返回0,如果传入的object本身就是0则返回0. 在使用时有两 ...

  5. ReverseInteger

    public class ReverseInteger { public static int reverse(int x) { long ret = 0; //如果是个位数,直接返回. if(x/1 ...

  6. codeforces 705A:Hulk

    Description Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely ta ...

  7. numpy array转置与两个array合并

    我们知道,用 .T 或者 .transpose() 都可以将一个矩阵进行转置. 但是一维数组转置的时候有个坑,光transpose没有用,需要指定shape参数, 在array中,当维数>=2, ...

  8. node express框架基本配置

    node express框架基本配置 初始化项目 express -e 安装依赖包 npm install 安装第三方包 npm install xxx --save-dev dos 运行node a ...

  9. ansible安装nginx

    ansible安装nginx(实现回滚发布功能:下一篇博客.没想到写长了) 一.准备工作 1.准备两台机器 sai: 192.168.131.132  ——> ansible的服务端 luojy ...

  10. 去除sql中不可见字符的n种方法

    CREATE TABLE [ASCII0127] ( Bin          INT, Dec          INT, Hex          VARCHAR(128), Abbr       ...