码迷,mamicode.com
首页 > Windows程序 > 详细

uoj206 [APIO2016]最大差分

时间:2018-05-08 11:07:34      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:type   log   ret   href   net   detail   love   i++   turn   

ref

#include "gap.h"
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
ll a[100005];
ll findGap(int T, int n){
    if(T==1){
        ll l=0, r=1000000000000000000ll, mn, mx;
        int lcnt=1, rcnt=n;
        while(lcnt<=rcnt && l<=r){
            MinMax(l, r, &mn, &mx);
            if(mn!=-1)  a[lcnt++] = mn;
            if(mx!=-1)  a[rcnt--] = mx;
            l = mn + 1;
            r = mx - 1;
        }
        ll re=0;
        for(int i=2; i<=n; i++)
            re = max(re, a[i]-a[i-1]);
        return re;
    }
    else{
        ll mn, mx;
        MinMax(0, 1000000000000000000ll, &mn, &mx);
        if(n<=2)    return mx-mn;
        ll lst=mn, len=(mx-mn-1)/(n-2)+1, s=mn+1, t, ans=0, lim=mx;
        for(int i=1; i<=n-2; i++){
            t = s + len - 1;
            if(t>=lim)  t = lim - 1;
            if(s>t) break;
            MinMax(s, t, &mn, &mx);
            if(mx!=-1){
                ans = max(mn - lst, ans);
                lst = mx;
            }
            s = t + 1;
        }
        ans = max(ans, lim-lst);
        return ans;
    }
}

uoj206 [APIO2016]最大差分

标签:type   log   ret   href   net   detail   love   i++   turn   

原文地址:https://www.cnblogs.com/poorpool/p/9006882.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!