【三分】[CodeForces

编程入门 行业动态 更新时间:2024-10-10 08:18:23

【三分】[<a href=https://www.elefans.com/category/jswz/34/1770097.html style=CodeForces"/>

【三分】[CodeForces

CodeForces - 579E
可以发现结果关于x的函数是一个单谷函数,所以三分。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 200000
int a[MAXN+10],n;
double l[MAXN+10];
void Read(int &x){char c;bool f=0;while(c=getchar(),c!=EOF){if(c=='-')f=1;if(c>='0'&&c<='9'){x=c-'0';while(c=getchar(),c>='0'&&c<='9')x=x*10+c-'0';if(f)x=-x;ungetc(c,stdin);return;}}
}
double get_poor(double x){int i;double sum=0,ret=0;for(i=1;i<=n;i++)l[i]=a[i]-x;for(i=1;i<=n;i++){sum+=l[i];if(sum<0)sum=0;ret=max(sum,ret);l[i]=-l[i];}sum=0;for(i=1;i<=n;i++){sum+=l[i];if(sum<0)sum=0;ret=max(sum,ret);}return ret;
}
int main()
{Read(n);int i;for(i=1;i<=n;i++)Read(a[i]);double l=-1e4,r=1e4,m1,m2,v1,v2;i=100;while(i--){m1=l+(r-l)/3;m2=m1+(r-m1)/2;v1=get_poor(m1);v2=get_poor(m2);if(v1>v2)l=m1;elser=m2;}printf("%.15lf\n",get_poor(l));
}

更多推荐

【三分】[CodeForces

本文发布于:2024-02-13 10:33:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1758234.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:CodeForces

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!