zoukankan      html  css  js  c++  java
  • https://codeforces.com/contest/1301/problem/B

    https://codeforces.com/contest/1301/problem/B
    如果填的这个数特别大,显然不优,如果数特别小,也不优,所以它是凸函数,可以二分(整数单峰函数二分模板题

    #include <iostream>
    #include <cstdio>
    #include <queue>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    #define inf 2147483647
    #define N 1000010
    #define p(a) putchar(a)
    #define For(i,a,b) for(long long i=a;i<=b;++i)
    
    using namespace std;
    long long T,n,l,r,mid;
    long long a[N],b[N];
    void in(long long &x){
        long long y=1;char c=getchar();x=0;
        while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
        while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
        x*=y;
    }
    void o(long long x){
        if(x<0){p('-');x=-x;}
        if(x>9)o(x/10);
        p(x%10+'0');
    }
    
    long long f(long long x){
        long long Max=0;
        For(i,1,n) if(a[i]!=-1) b[i]=a[i];else b[i]=x;
        For(i,1,n-1) Max=max(Max,b[i]>b[i+1]?b[i]-b[i+1]:b[i+1]-b[i]);
        return Max;
    }
    
    signed main(){
        in(T);
        while(T--){
            in(n);
            For(i,1,n) in(a[i]);
            l=1;r=1e10;
            while(l<r){
                mid=(l+r)>>1;
                if(f(mid-1)<=f(mid)) r=mid;
                else l=mid+1;
            }
            o(f(l-1));p(' ');o(l-1);p('
    ');
        }
        return 0;
    }
  • 相关阅读:
    每日日报8月12日
    每日日报8月15日
    每日日报8月18日
    每日日报8月9日
    九月29号——动手又动脑
    今日总结
    每周总结
    今日总结
    周总结
    今日总结
  • 原文地址:https://www.cnblogs.com/war1111/p/12532161.html
Copyright © 2011-2022 走看看