【NOIP2015】【Luogu2678】跳石头

problem
solution
codes
//二分答案
//QAQ注意:起点和终点也是有石头的w
#include<iostream>
#include<algorithm>
#define maxn 100010
using namespace std;
int ll, n, m;
int a[maxn];
bool check(int x){
    int t=0, co=0; //起点的石头不能搬走哦
    for(int i = 1; i <= n+1; i++){
        if(a[i]-a[t]<x)co++;//如果距离小于我二分的答案x,那么这块石头需要搬走
        else t = i;//不然我就跳过来
    }
    if(co > m)return false;//如果要搬走的石头多于m块,那么这个解太大了
    return true;
}
int main(){
    cin>>ll>>n>>m;
    for(int i = 1; i <= n; i++)cin>>a[i];
    a[n+1] = ll;
    sort(a,a+n+1);  //排个序防炸输入数据
    int l = 1, r = ll;
    while(l <= r){
        int mid = (l+r)/2;
        if(check(mid))l = mid+1;
        else r = mid-1;
    }
    cout<<r<<"\n";
    return 0;
}

转载于:https://www.cnblogs.com/gwj1314/p/9444839.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值