标签:inpu pen output 子序列 space 连续序列 题解 序列 constrain
1 #include <cstdio> 2 #include <cstring> 3 #define N 300010 4 using namespace std; 5 int n,k; 6 double l,r,mid,a[N],b[N],eps=1e-5; 7 bool check(int x) 8 { 9 double p=0; 10 for (int i=k;i<=n;i++) 11 { 12 if (b[i]-p>=0) return 1; 13 if (b[i-k+1]<p) p=b[i-k+1]; 14 } 15 return 0; 16 } 17 int main() 18 { 19 freopen("average.in","r",stdin),freopen("average.out","w",stdout),scanf("%d%d",&n,&k); 20 for (int i=1;i<=n;i++) scanf("%lf",&a[i]),r+=a[i]; 21 while (r-l>eps) 22 { 23 double mid=(l+r)/2.0; b[0]=0; 24 for (int i=1;i<=n;i++) a[i]-=mid,b[i]=b[i-1]+a[i]; 25 if (check(mid)) l=mid; else r=mid; 26 for (int i=1;i<=n;i++) a[i]+=mid; 27 } 28 printf("%.5lf",l); 29 }
标签:inpu pen output 子序列 space 连续序列 题解 序列 constrain
原文地址:https://www.cnblogs.com/Comfortable/p/10358964.html