zoukankan      html  css  js  c++  java
  • HDU 4004:The annual Games(答案二分)

    难在judge函数的编写,之前写了个复杂度n的judge函数。。。妥妥的TLE了

    #include"cstdio"
    #include"cmath"
    #include"algorithm"
    #include"cstring"
    #define MAXN 500010
    using namespace std;
    int n,step,len,ans;
    int stone[MAXN];
    bool judge(int abi)
    {   int temp=0,l,mark=0,t;
        for(int i=0;i<=step;i++){
            while(temp+abi>=stone[mark]&&mark<=n)
                t=stone[mark++];
            temp=t;
            if(temp>=len) return true;
        }
        if(temp>=len) return true;
        return false;
    }
    int get_ans()
    {   int low=0,high=len,mid;
        while(high>=low){
        mid=low+(high-low)/2;
        if(judge(mid)) high=mid-1;
        else low=mid+1;
        }
        return mid;
    }
    int main()
    {   while(scanf("%d%d%d",&len,&n,&step)!=EOF){
            for(int i=0;i<n;i++) scanf("%d",&stone[i]);
            stone[n]=len;
            sort(stone,stone+n);
            printf("%d
    ",get_ans());
        }
        return 0;
    }
     
    View Code
  • 相关阅读:
    mysql 统计数据库基本资源sql
    java ffmpeg (Linux)截取视频做封面
    shutil模块
    json模块与pickle模块
    hashlib模块
    sys模块
    os模块
    paramiko模块
    Python reduce() 函数
    瀑布流展示图片
  • 原文地址:https://www.cnblogs.com/luxiaoming/p/4705220.html
Copyright © 2011-2022 走看看