zoukankan      html  css  js  c++  java
  • hdu 5248 序列变换

    中文题意,略(但弱鸡的我还是把题目读错了,一直到读题解的时候才发现,弱鸡总会读错题目,我以为跑一下lis就行了,太天真)

    但现在还是没有想到为什么会用二分(虽然大家都是这么说的,而且这是二分专题,emmm)

    #include <set>
    #include <map>
    #include <queue>
    #include <stack>
    #include <math.h>
    #include <vector>
    #include <string>
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <iostream>
    #include <algorithm>
    #define zero(a) fabs(a)<eps
    #define max( x, y )  ( ((x) > (y)) ? (x) : (y) )
    #define min( x, y )  ( ((x) < (y)) ? (x) : (y) )
    #define lowbit(x) (x&(-x))
    #define debug(a) cerr<<#a<<"=="<<a<<endl
    typedef long long ll;
    const double pi=acos(-1.0);
    const double eps=1e-8;
    const int inf=0x3f3f3f3f;
    const ll linf=0x3f3f3f3f3f3f3f3f;
    const int maxn = 1e5;
    using namespace std;
    
    int a[maxn],b[maxn],n;
    
    int check(int x)
    {
    //    bool ok=true;
        b[0]=a[0]-x;
        for(int i=1;i<n;i++){
            if(a[i]>b[i-1]){
                b[i]=max(b[i-1]+1,a[i]-x);
            }
            else{
                b[i]=min(b[i-1]+1,a[i]+x);
            }
            if(b[i]<=b[i-1])return false;
        }
        return true;
    }
    
    int main()
    {
        int t;
        scanf("%d",&t);
        int cas=1;
        while(t--)
        {
            scanf("%d",&n);
            memset(a,0,sizeof(a));
            for(int i=0;i<n;i++){
                scanf("%d",&a[i]);
            }
    
            int l=0,r=inf;
            int mid,as;
            while(l<=r){
                mid=(l+r)>>1;
    //            printf("test
    ");
                if(check(mid)){
                    r=mid-1;
                    as=mid;
                }
                else{
                    l=mid+1;
                }
            }
            printf("Case #%d:
    ",cas++);
            printf("%d
    ",as);
        }
        return 0;
    }
    /*
    2
    2
    1 10
    3
    2 5 4
    */
  • 相关阅读:
    Echart 动态生成series数据
    转换Excel格式
    .NET接收邮件下载邮件附件——openpop.net
    百度Echart 地图
    mobiscroll 日期问题
    jQuery自动完成插件flexselect
    HTML5 video 连续播放视频
    team foundation server 工具的使用
    实现主成分分析与白化
    白化(预处理步骤)【转】
  • 原文地址:https://www.cnblogs.com/lalalatianlalu/p/7819987.html
Copyright © 2011-2022 走看看