1 条题解

  • 1
    @ 2026-1-12 17:58:14
    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e5+5;
    int n,m,x[N],ans,l=0,r=1e9+5;
    int f(int t){
        int tot=1,last=1;
        for(int i=2;i<=n;i++)
            if(x[i]-last>=t){
                tot++;
                last=x[i];
            }
        return tot>=m;
    }
    int main(){
        cin>>n>>m;
        for(int i=1;i<=n;i++)
            cin>>x[i];
        sort(x+1,x+1+n);
        while(l<=r){
            int mid=(l+r)/2;
            if(f(mid)){
                l=mid+1;
                ans=mid;
            }
            else
                r=mid-1;
        }
        cout<<ans;
        return 0;
    }
    
    • 1

    [USACO05FEB] 进击的奶牛 Aggressive Cows G

    信息

    ID
    791
    时间
    1000ms
    内存
    125MiB
    难度
    3
    标签
    递交数
    1
    已通过
    1
    上传者