11
13
2015
0

[BZOJ 4318] OSU!

期望题,维护期望和平方的期望就可以计算

#include <cstdio>
#include <memory.h>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cctype>
 
using namespace std;
 
void read(double &num)
{
    num=0;
    bool after=0;
    double bei=1;
    char tmpc;
    do
    {
        tmpc=getchar();
    }
    while (!isdigit(tmpc));
    while (isdigit(tmpc))
    {
        if (after)
        {
            bei/=10;
            num=num+(tmpc-'0')*bei;
        }
        else
            num=num*10+tmpc-'0';
        tmpc=getchar();
        if (tmpc=='.')
        {
            after=1;
            tmpc=getchar();
        }
    }
}
int main() {
    register int n;
    scanf("%d",&n);
    register double f = 0,g = 0,ans = 0, p;
    while (n--) {
        read(p);
        ans += (3*f+3*g+1)*p;
        g = (g+2*f+1) * p;
        f = (f+1) * p;
    }
    printf("%.1f\n",ans);
}
Category: 动态规划 | Tags: | Read Count: 657

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com