P1365 WJMZBMR打osu! / Easy

JIsoo

期望得分要dp,然后期望长度是有关系的

那就一块dp

#include<cstdio>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<cmath>
#include<algorithm>
using namespace std;
template<class T>inline void read(T &x)
{
    x=0;register char c=getchar();register bool f=0;
    while(!isdigit(c))f^=c=='-',c=getchar();
    while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
    if(f)x=-x;
}
template<class T>inline void print(T x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar('0'+x%10);
}
int n;
long double f[1000005];
string s;
long double len;
int main(){
//	ios::sync_with_stdio(false);
	cin>>n;
	cin>>s;
	for(int i=1;i<=n;++i){
		if(s[i-1]=='x'){
			f[i]=f[i-1];
			len=0;
		}
		if(s[i-1]=='o'){
			f[i]=f[i-1]+len*2+1;
			len++;
		}
		if(s[i-1]=='?'){
			f[i]=0.5+len+f[i-1];
			len=(len+1)/2;
		}
	}
	printf("%.4Lf",f[n]);
    return 0;
}

posted @ 2021-10-19 16:01  Simex  阅读(30)  评论(0编辑  收藏  举报