3450:tyvj1952 Easy Time limit:10 Sec Memory limit:128 MB
submit:468 solved:353
[Submit] [Status] [Discuss] Description
One day WJMZBMR is playing osu~~~ but he is too weak to push, some places entirely by luck: (
Let's simplify the rules of the game.
Have n click to do, success is O, failure is x, score is calculated according to comb, continuous a comb there is a*a points, comb is a great continuous o.
Like Ooxxxxooooxxx, the score is 2*2+4*4=4+16=20.
Sevenkplus Idle panic To see he played a plate, some places have nothing to do with luck either O or x, some places o or x each have 50% probability, with the number to express.
For example, OO?XX is a possible input.
So what is the expected score of WJMZBMR this OSU?
Like Oo?xx's words, "o" is the word Oooxx = 9, x is ooxxx = 4
The natural expectation is (4+9)/2 = 6.5.
Input
The first line is an integer n, which indicates the number of clicks
Next string, each character is an ox? In one of
Output
A single line of floating-point numbers indicates the answer
Rounded to 4 digits after the decimal point
If the fear of precision kneeling suggested with a long double or extended
Sample Input4
????
Sample Output4.1250
n<=300000
OSU, it's fun.
WJMZBMR technology is OK (fog), X is basically very few
Hintsource
We all love the Gyz Cup.
Solution
One-eye probabilities and expectations
Because to continuous comb, so first analysis of the current continuous $x$ next time is ' O ' contribution is $2x+1$
Then meet ' X ' and break off and meet '? ' Binary, move it.
Code
#include <iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespacestd;#defineMAXN 300010CharOSU[MAXN];intN;DoubleP[maxn],ans;intMain () {scanf ("%d", &n); scanf"%s", osu+1); for(intI=1; i<=n; i++) Switch(Osu[i]) { Case 'o': ans+=2*p[i]+1; p[i+1]=p[i]+1.0; Break; Case 'x': p[i+1]=0.0; Break; Case '?': ans+=p[i]+0.5; p[i+1]= (p[i]+1.0)/2.0; Break; } printf ("%.4lf\n", ans); return 0;}
"BZOJ-3450" tyvj1952easy probability and expectation DP