蒟蒻WA#1#11的二分答案求助
查看原帖
蒟蒻WA#1#11的二分答案求助
516867
SZnP楼主2022/11/27 17:16
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef int Int;
using namespace std;
int l,n,m,a[50000],le,ri,mi,last,chans;
bool check()
{
    last=a[0];chans=0;
    for(int i=1;i<n;i++)
    {
        if(a[i]-last<mi){chans++;}
        else last=a[i];
    }
    return chans<=m?true:false;
}
int main()
{
    cin>>l>>n>>m;
    if(n==0&&m==0){cout<<l;return 0;}
    for(Int i=1;i<=n;i++)
        cin>>a[i];
    a[0]=0;a[n+1]=l;
    n+=2;
    le=0;ri=a[n-1];
    while(ri-le>5)
    {
        mi=(le+ri)/2;
        if(check())le=mi;
        else ri=mi;
    }
    for(int i=ri;i>=le;i--)
    {
        mi=i;
        if(check()){cout<<mi;return 0;}
    }
    return 0;
}

rt,#11输出比正确答案少1

thx

2022/11/27 17:16
加载中...