最小值的最大值问题

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

解题思路:

取得最大距离与最小距离,那么移除石头后的最短距离必然在之之间
那么我们可以再这个区间内对结果进行二分,看二分出的最短距离是否能符合移除m个石头的方案即可,如果求出的第一个mid符合题意不要停止查找,看是否有更大的解

#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>

using namespace std;
#define mod 1e9+7
#define N 50005
#define inf 0x3f3f3f3f
typedef long long ll;
int a[N];
int n;
int ok(int mid)
{
    int ans=0,j=0;
    for(int i=1; i<=n+1; i++)
    {
        if(a[i]-a[j]<mid)
            ans++;
        else
            j=i;

    }
    return ans;

}
int main()
{
    //freopen("E:\\in.txt","r",stdin);
    ll len;
    int m;
    while(cin>>len>>n>>m)
    {

        for(int i=1; i<=n; i++)
            cin>>a[i];
        a[n+1]=len;
        a[0]=0;
        sort(a,a+2+n);
        ll l=0,r=len,mid;
        while(l<=r)
        {
            mid=(l+r)>>1;
            if(ok(mid)>m)
                r=mid-1;
            else
                l=mid+1;

        }
        cout<<r<<endl;

    }



    fclose(stdin);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
超级编辑框,日期,时间,ip,电话号码,银行卡号, 等格式可以自己自定义。 简单写了个调用列子,各位高手可以自己完善这个控件。 帮助文档和黑月OCX驱动支持库已经打包在一起了 BUG,易语言控件属性界面直接设定属性值无效,必须用代码指定才可以。 用黑月OCX驱动支持库调用,暂时没发现BUG 以下是官方关于控件的介绍,机器翻译的内容,凑合看吧: SftMask/OCX提供了许多独特的特性,这些特性简化了应用程序中的数据输入和数据验证。SftMask/OCX支持各种完全可自定义的数字、日期/时间和蒙面输入。 自动完成并建议具有完整应用程序控制的特性。 文本 档案 目录 插入/覆盖模式 多层撤消 内建误差图像处理错误和警告的工具提示 带有预定义位置持有者和用户可定义字符范围的蒙面输入 输入掩码可以混合日期、时间、数字输入、掩码和文字。 不需要提示字符(但可能),因为输入字段可以使用突出文本的字体。 文字(常量)数据不加下划线。 数字数据输入(带有格式选项和用户可定义的数字和分数) 任选弹出式计算器 弹出窗口允许使用+,-,*,/进行中间计算 数字(整数)数据输入 任选上下按钮 (旋转按钮) 用户定义的最小/最大范围 日期输入弹出日历 内建弹出日历 用户可定义的一周的第一天 可选周数 事件突出显示特定日期为日历显示 可定义的最小/最大日期 使用系统的默认日期格式或指定您自己的格式 日期值易于检索和设置 时间输入 使用系统的默认时间格式或指定您自己的格式 时间值易于检索和设置 Windows主题支撑 内置字幕,简化字幕和编辑控件对齐方式,减少窗体上控件的数量。 OLE拖拽支撑 使用activex数据对象(Ado)的可选数据绑定模式 左对齐或右对齐 日期/时间、货币和数字格式函数 控件在没有输入焦点时可以显示用户定义的文本。 自动推进在相同的对话框/窗体上的下一个控件,当数据输入有效时。 选项卡键可以在控件中任意使用,以在不同字段之间移动(例如在日期或时间值中)。 通过双接口实现最佳性能 所有支持的平台上的Unicode支持 基于Atl的控件,不需要MFC DLL或其他DLL(Comctl32.dll)弹出日历使用) 非基于Windows编辑控件类 版税 您开发的任何应用程序都可以在只运行时模式下免费使用SftMask/OCX版税;设计时功能是不可用的。每个需要访问设计时特性的用户(开发人员)必须授权SftMask/OCX的副本。 源代码 控件和属性页(用Microsoft Visual C+编写,使用ATL框架)在我们的企业许可程序下可供选择。您开发的任何应用程序都可以使用SftMask/OCX免版税(有些限制适用),只要您的应用程序只附带可再发行的文件。 支持的语言 SftMask/OCX支持所有流行的ActiveX(OCX)平台,如Visual Studio.NET、Visual Basic、Visual C+等。特性限制可能根据所使用的平台而存在。这些通常是由平台造成的,而不是我们的控制产品,它实现了当前的ActiveX控件标准规范。 支持的环境 SftMask/OCX使用相同的属性、事件和方法集,通过Windows 10及其服务器版本支持Windows 2000。 完全支持Unicode字符集。 DBCS字符集是不支持。 Windows 98和Windows ME是不再支持。为了支持这些平台,必须使用SftMask/OCX 6.5。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值