其他分享
首页 > 其他分享> > 做题记录 Luogu P1365

做题记录 Luogu P1365

作者:互联网

P1365 WJMZBMR打osu! / Easy - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

分情况递推,维护一次的和。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 300005
int n;
char s[N];
double x1[N], f[N];
signed main()
{
	scanf("%d", &n);
	scanf("%s", s + 1);
	for(int i = 1; i <= n; i++)
	{
		if(s[i] == 'o')
		{
			x1[i] = (x1[i - 1] + 1);
			f[i] = f[i - 1] + (2 * x1[i - 1] + 1) ;
		}
		else if(s[i] == 'x')
		{
			f[i] = f[i - 1];
		}
		else if(s[i] == '?')
		{
			x1[i] = (x1[i - 1] + 1) * 0.5;
			f[i] = f[i - 1] + (2 * x1[i - 1] + 1) * 0.5;
		}
	}
	printf("%0.4lf", f[n]);
	return 0;
}

标签:P1365,cn,记录,int,Luogu,scanf,long,define
来源: https://www.cnblogs.com/fanypcd/p/15032195.html