• 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;
    }
    
  • 相关阅读:
    jQuery 工具函数
    cdh 5.13 centos6.9安装
    centos 6.9 NTP基准时间服务器配置
    cloudera cdh5.13.0 vmware 快速安装
    centos 7.3+nginx+jira(.bin)+mysql
    zabbix 3.2.6+centos 7 +nginx 1.12+ mysql 5.6+ Grafana +php 5.6
    centos 6.9 +nginx 配置GIT HTTPS服务器(证书采用自签名)
    好难啊 姿态解算 算是解决了
    stm32 iic读取mpu6050失败 改用串口
    stm32 延时函数 delay_ms 范围
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11272272.html
Copyright © 2020-2023  润新知