3450: Tyvj1952 Easy

题目链接

题目大意:有一个字符串,由 ’ 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 std;
 
int 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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值