3450: Tyvj1952 Easy

来源:互联网 发布:fm2药淘宝交易 编辑:程序博客网 时间:2024/06/06 20:52

题目链接

题目大意:有一个字符串,由 ’ o ‘, ’ x ‘, ’ ? ’ 组成,连续的 Y 个  ’ o ’ 对答案的贡献是 Y ^ 2,而 ’ x ’ 不会产生贡献,’ ? ’ 代表有 50% 的几率代表 ’ o ‘,另一半代表 ’ x ‘,求期望的贡献

Lof[i]i
(1)s[i]=xL=0,f[i]=f[i1]
(1)s[i]=oL=L+1,L2(L+1)22L+1f[i]=f[i1]+2L+1
(1)s[i]=?L=L+12,f[i]=f[i1]+2L+12

我的收获:对题目的分析……

#include<iostream>#include<cstdio>#include<algorithm>#include <cmath>#include <cstring>using namespace stdint n;double f[300005],L;char s[300005]; void init(){    scanf("%d%s",&n,s+1);    for(int i=1;i<=n;i++){        switch(s[i])        {            case 'x':f[i]=f[i-1],L=0;break;            case 'o':f[i]=f[i-1]+2*L+1,L=L+1;break;            default :f[i]=f[i-1]+(2*L+1)/2,L=(L+1)/2;        }    }    printf("%.4lf\n",f[n]); } int main(){    init();    return 0;}