[BZOJ4318] OSU!

题目链接

首先根据题设直接设期望: $ E(G(x))$ 表示到x的期望得分.

因为:
\[ E(x + \Delta) = E(x) + E(\Delta) \]
并且期望的本质实际上是积分, 所以我们只要计算每一个点对应的增量\(\Delta\)就可以计算当前的期望值.

发现\(E(x ^ 3)\) 的增量为\(3E(x ^ 2) + 3E(x) + 1\)

\(E(x ^ 2)\)的增量为\(2E(x) + 1\)

然后直接dp计算即可.

Code

#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a), i##_end_ = (b); i <= i##_end_; ++i)
#define drep(i, a, b) for(int i = (a), i##_end_ = (b); i >= i##_end_; --i)
#define clar(a, b) memset((a), (b), sizeof(a))
#define debug(...) fprintf(stderr, __VA_ARGS__)
typedef long long LL;
typedef long double LD;
int read() {
    char ch = getchar();
    int x = 0, flag = 1;
    for (;!isdigit(ch); ch = getchar()) if (ch == '-') flag *= -1;
    for (;isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x * flag;
}
void write(int x) {
    if (x < 0) putchar('-'), x = -x;
    if (x >= 10) write(x / 10);
    putchar(x % 10 + 48);
}

const int Maxn = 100009;
int n;
double f[Maxn];
double Expection[Maxn][4];
double g[Maxn];

void init() {
    n = read();
    rep (i, 1, n) scanf("%lf", &f[i]);
}

void solve() {
    rep (i, 1, n) {
        Expection[i][1] = (Expection[i - 1][1] + 1) * f[i];
        Expection[i][2] = (Expection[i - 1][2] + 2 * Expection[i - 1][1] + 1) * f[i];
        Expection[i][3] = Expection[i - 1][3] + (3 * Expection[i - 1][2] + 3 * Expection[i - 1][1] + 1) * f[i];
    }

    printf("%.1lf\n", Expection[n][3]);
}

int main() {
    freopen("BZOJ4318.in", "r", stdin);
    freopen("BZOJ4318.out", "w", stdout);

    init();
    solve();

#ifdef Qrsikno
    debug("\nRunning time: %.3lf(s)\n", clock() * 1.0 / CLOCKS_PER_SEC);
#endif
    return 0;
}

转载于:https://www.cnblogs.com/qrsikno/p/10325441.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值