题意:题意看不懂,根据样例猜了一下,给一个序列,算出所有子序列的和。
思路:第i个数的贡献为i * (n - i + 1) * a[i]。
代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n;
double ans, x;
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
scanf("%d", &n);
ans = 0.0;
for (int i = 1; i <= n; i++) {
scanf("%lf", &x);
ans += x * i * (n - i + 1);
}
printf("%.2lf", ans);
return 0;
}