标签:
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4318
考虑每一位对答案的贡献为f[i];则f[i]=p[i]*(3*e1[i-1]+3*e2[i-1]+1),e1[i]表示到i位连续1的期望,e2[i]就是平方的期望。把每一位的贡献加起来就是答案。
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 #include<cmath> 6 #define maxn 100005 7 using namespace std; 8 int n; 9 typedef double ld; 10 ld ans,p[maxn],f[maxn],e1[maxn],e2[maxn]; 11 int main(){ 12 scanf("%d",&n); 13 for(int i=1;i<=n;i++)scanf("%lf",&p[i]); 14 for(int i=1;i<=n;i++){ 15 f[i]=p[i]*(1+3*e1[i-1]+3*e2[i-1]); 16 e1[i]=p[i]*(e1[i-1]+1);e2[i]=p[i]*(e2[i-1]+2*e1[i-1]+1); 17 } 18 for(int i=1;i<=n;i++)ans+=f[i]; 19 printf("%.1lf\n",ans); 20 return 0; 21 }
题目链接:http://codeforces.com/problemset/problem/235/B
bzoj4318: OSU!&&CF235BLet's Play Osu!
标签:
原文地址:http://www.cnblogs.com/longshengblog/p/5789769.html