• luogu1419 寻找段落 (二分,单调队列)


    单调队列存坐标

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #define R(a,b,c) for(register int  a = (b); a <= (c); ++ a)
    #define nR(a,b,c) for(register int  a = (b); a >= (c); -- a)
    #define Max(a,b) ((a) > (b) ? (a) : (b))
    #define Min(a,b) ((a) < (b) ? (a) : (b))
    #define Fill(a,b) memset(a, b, sizeof(a))
    #define Abs(a) ((a) < 0 ? -(a) : (a))
    #define Swap(a,b) a^=b^=a^=b
    #define ll long long
    
    #define ON_DEBUG
    
    #ifdef ON_DEBUG
    
    #define D_e_Line printf("
    
    ----------
    
    ")
    #define D_e(x)  cout << #x << " = " << x << endl
    #define Pause() system("pause")
    #define FileOpen() freopen("in.txt","r",stdin);
    
    #else
    
    #define D_e_Line ;
    #define D_e(x)  ;
    #define Pause() ;
    #define FileOpen() ;
    
    #endif
    
    struct ios{
        template<typename ATP>ios& operator >> (ATP &x){
            x = 0; int f = 1; char c;
            for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-')  f = -1;
            while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
            x*= f;
            return *this;
        }
    }io;
    using namespace std;
    
    const int N = 100007;
    
    int n, lenS, lenT;
    int a[N];
    double b[N], sum[N];
    inline bool Check(double mid){ 
        R(i,1,n){
        	sum[i] = sum[i - 1] + (double)a[i] - mid;
        }
        int *q = new int[n + 3];
        int h = 1, t = 0;
        R(i,lenS,n){  
            while(h <= t && sum[i - lenS] < sum[q[t]]) --t;
            q[++t] = i - lenS;
            if(h <= t && q[h] < i - lenT) ++h;
            if(h <= t && sum[i] - sum[q[h]] >= 0){
            	delete []q;
            	return true;
            }
        }
        delete []q;
        return false;  
    }  
    int main(){
    	io >> n >> lenS >> lenT;
    	R(i,1,n){
    		io >> a[i];
    	}
    	double l = -10000, r = 10000;
    	while(r - l > 1e-6){
    		double mid = (l + r) / 2.0;
    		if(Check(mid))
    			l = mid;
    		else
    			r = mid;
    	}
    	printf("%.3lf", l);
    
    	return 0;
    }
    
  • 相关阅读:
    Linux下环境变量配置方法梳理(.bash_profile和.bashrc的区别)
    Mac下安装配置Python2和Python3并相互切换使用
    精通Python自动化脚本
    idea之Git
    python面向对象之:细分类的组成成员
    new string("abc")创建了几个对象
    进程和线程的主要区别
    Leetcode 572 另一个树的子树
    Leetcode 二叉树的坡度
    Leetcode 559 N叉树的最大深度
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11272272.html
Copyright © 2020-2023  润新知