Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] C A Weakness and Poorness

來源:互聯網
上載者:User

標籤:

f(x)是個凹函數,三分即可,計算方案的時候dp一下。掛精度很坑,指定迴圈次數正解?

#include<bits/stdc++.h>using namespace std;const double eps = 1e-11;const int maxn = 2e5+5;double a[maxn];double d1[maxn],d2[maxn];int n;inline double cal(double x){    double a1 = 0., a2 = 0.;    for(int i = 1; i <= n; i++){        d1[i] = max(0.,d1[i-1])+a[i]-x;        a1 = max(a1,d1[i]);        d2[i] = min(0.,d2[i-1])+a[i]-x;        a2 = min(a2,d2[i]);    }    return max(fabs(a1),fabs(a2));}int main(){    //freopen("in.txt","r",stdin);    scanf("%d",&n);    for(int i = 1; i <= n; i++) scanf("%lf",a+i);    double L = -1e4, R = 1e4;    double M1v,M2v;    while(R-L>eps){        double M1 = L+(R-L)/3, M2 = L+(R-L)/3*2;        M1v = cal(M1), M2v = cal(M2);        if(abs(M1v-M2v)<eps){            L = M1; R = M2;        }else {            if(M1v > M2v){                L = M1;            }else {                R = M2;            }        }    }    printf("%.15lf",(cal(L)+cal(R))/2);    return 0;}

 

Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] C A Weakness and Poorness

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.