Report problem solving: luogu P3853 [TJOI2007] signs set

Topic links: P3853 [TJOI2007] signs set
is a half of water, then you \ (WA \) . It is simply practicing the morning practice and that similar questions questions.
Dichotomous answer to the complexity of the \ (O (Nlogl) \) , by this question.
However, it should be noted that, if divisible, \ (cnt - \) , responsible like me to \ (80pts \) .

\(Code\):

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int l,n,k,ans=0;
int a[1000005];
int judge(int x)
{
    int cnt=0;
    int last=0;
    for(int i=0;i<=n+1;i++)
    {
        if(a[i]-last>x)
        {
            cnt+=(a[i]-last)/x;
            if((a[i]-last)%x==0) cnt--;
        }
        last=a[i];
    }
    if(cnt>k) return 0;
    else return 1;
}
int main()
{
    //freopen("data.in","r",stdin);
    //freopen("baoli.out","w",stdout);
    scanf("%d%d%d",&l,&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    int ll=1,rr=l;
    a[n+1]=l;
    while(ll<=rr)
    {
        int mid=(ll+rr)>>1;
        if(judge(mid)) ans=mid,rr=mid-1;
        else ll=mid+1;
    }
    printf("%d\n",ans);
    return 0;
} 

Half really amazing ah

Guess you like

Origin www.cnblogs.com/tlx-blog/p/12294714.html