3450:tyvj1952 Easy Time limit:10 Sec Memory limit:128 MB
submit:431 solved:325
[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
HINT Source
We all love the Gyz Cup.
Exercises
Probability/expectation + dynamic planning
Set L to the length of the desired O
When the next number is X, the l=0
When the next number is O, l++, ans=ans+ (l+1) * (l+1)-l*l
=ans+l^2+2*l+1-l^2
=ans+2*l+1
When the next number is, L may be 0 or l+1, so L's expected value is (0+l+1)/2
In the same vein, ans may add 0 or 2*l+1, so the desired value of ans is added to the number of (0+2*l+1)/2
Then you can move the rules directly.
1#include <bits/stdc++.h>2 using namespacestd;3 intMain ()4 {5 intn,i;6 Doubleans=0.0, l=0.0;7 CharA;8scanf"%d\n",&n);9 for(i=1; i<=n;i++)Ten { Onescanf"%c",&a); A if(a=='o') {ans+= (l*2.0+1.0); l++;} - Else if(a=='x') l=0.0; - Else{ans=ans+ (l*2.0+1.0)*0.5; L= (L +1.0)*0.5;} the } -printf"%.4LF", ans); - fclose (stdin); - fclose (stdout); + return 0; -}
Bzoj 3450:tyvj1952 Easy expectation/probability, dynamic planning