cf#320 Div.2 Problem E Weakness and Poorness
2015-09-17 13:14
429 查看
这题的代码是参考比赛中大神的AC代码的,据说用到了三分思想和前缀和,这里先记下来,日后再消化
#include <iostream> #include <cstring> #include <cstdio> #include <cmath> using namespace std; int N; int A[200005]; double f(double x){ double res=0,s1=0,s2=0; for(int i=0;i<N;i++){ if(s1<0)s1=A[i]-x; else s1+=A[i]-x; if(s2>0)s2=A[i]-x; else s2+=A[i]-x; res=max(res,max(fabs(s1),fabs(s2))); } return res; } int main(){ while(scanf("%d",&N)!=EOF){ for(int i=0;i<N;i++) scanf("%d",&A[i]); double l=-10000,r=10000,m1,m2,a1,a2,ans=1e233; for(int i=0;i<128;i++){ m1=l+(r-l)/3; m2=l+(r-l)/3*2; a1=f(m1),a2=f(m2); ans=min(ans,min(a1,a2)); if(a1<a2)r=m2; else l=m1; } printf("%.15lf",ans); } return 0; }
相关文章推荐
- 【CF 应用开发大赛】MZCMS内容管理系统
- windows 7 玩不了CF 打开之后进入安全登录就自动关闭
- Cloud Foundry社区周报 2015/2/17
- Cloud Foundry社区周报 2015/2/27
- 使用cf_nise_installer安装CloudFoundry出现not monitored问题
- CF Round#2
- cf3月活动大全 3月活动汇总2015
- CF#277.5div2
- HDU4355--Party All the Time,HDU3714--Error Curvese三分法
- CSU 1548 Road And Bridge acm 三分
- HDU 4717 The Moving Points
- Codeforces Round #260 (Div. 2)
- [HDU4355][三分]Party All The Time
- Codeforces538F A Heap of Heaps【分块+差分求前缀和】
- cf_301
- cf_297
- Hdu 5307 He is Fly 2015ACM多校对抗赛第二场
- Hdu 4609 FFT
- 2015ACM多校对抗赛第四场 hdu 5327
- [cf509B]Painting Pebbles