其他分享
首页 > 其他分享> > 做题记录 Luogu P1654

做题记录 Luogu P1654

作者:互联网

P1654 OSU! - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

递推,分别维护一次和二次的和。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
int n;
double p[N], x1[N], x2[N], f[N];
signed main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		scanf("%lf", &p[i]);
	}
	for(int i = 1; i <= n; i++)
	{
		x1[i] = (x1[i - 1] + 1) * p[i];
		x2[i] = (x2[i - 1] + 2 * x1[i - 1] + 1) * p[i];
		f[i] = f[i - 1] + (3 * (x2[i - 1] + x1[i - 1]) + 1) * p[i];
	}
	printf("%0.1lf", f[n]);
	return 0;
}

标签:cn,记录,int,Luogu,namespace,long,P1654,define
来源: https://www.cnblogs.com/fanypcd/p/15032184.html