题目链接:https://www.luogu.com.cn/problem/P1365
题解地址:https://www.luogu.com.cn/blog/five20/solution-p1365
实现代码如下:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300030;
int n;
char s[maxn];
double f[maxn], g[maxn];
int main() {
scanf("%d%s", &n, s+1);
for (int i = 1; i <= n; i ++) {
if (s[i] == 'x') f[i] = f[i-1], g[i] = 0;
else if (s[i] == 'o') f[i] = f[i-1] + 2 * g[i-1] + 1, g[i] = g[i-1] + 1;
else f[i] = f[i-1] + g[i-1] + 0.5, g[i] = (g[i-1] + 1) / 2;
}
printf("%.4lf
", f[n]);
return 0;
}