BZOJ 3450: Tyvj1952 Easy, bzojtyvj1952

Source: Internet
Author: User

BZOJ 3450: Tyvj1952 Easy, bzojtyvj1952

Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 874 Solved: 646
[Submit] [Status] [Discuss] Description

One day, WJMZBMR is playing osu ~~~ But he is too weak, and in some places he depends entirely on luck :(
Let's simplify the rules of this game.
There are n clicks to do. If the operation succeeds, it is o. If the operation fails, it is x. The score is calculated by comb. For a consecutive comb, there is a * a score, comb is a great continuous o.
For example, if ooxxxxooxxx is used, the score is 2*2 + 4*4 = 4 + 16 = 20.
When Sevenkplus is idle, it seems that he has played a disk. In some places, it is irrelevant to luck, either o or x, and in some places, o or x has a 50% possibility? Number.
For example, oo? Xx is a possible input.
So what is the expected osu score of WJMZBMR?
For example, oo? Xx ,? If it is o, it is oooxx => 9. If it is x, it is ooxxx => 4.
The expectation is (4 + 9)/2 = 6.5.

Input


The first line is an integer n, indicating the number of clicks.
The next string, each character is ox? One

Output

A row with a floating point number indicates the answer
Rounded to four decimal places
If you are afraid of accuracy, we recommend using long double or extended

Sample Input4
????
Sample Output4.1250


N <= 300000
Osu is fun.
WJMZBMR technology is still good (FOG), and x is rarely used.
HINT Source

We all love GYZ cups.

$ Dp [I] [1] $ indicates the expected score when the $ I $ point is reached. $ dp [I] [0] $ indicates the expected score when the $ I $ point is reached. the maximum length of $ o $ is considered for transfer for $ x $, this round cannot score $ dp [I] [1] = dp [I-1] [1], dp [I] [0] = 0 $ for $ o $, this round of score is $ (l + 1) ^ 2 = l ^ 2 + 2 * l + 1 $, $ l ^ 2 $ which we have obtained before, $2 * l + 1 $ contribution to this round of answers $? $. I thought too much at the beginning. In fact, it is very simple. It is just to divide the above two cases into two.
 1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 using namespace std; 6 const int MAXN=1e6+10; 7 const int INF=0x7fffff; 8 inline int read() 9 {10     char c=getchar();    int flag=1,x=0;11     while(c<'0'||c>'9')    {if(c=='-')    flag=-1;c=getchar();}12     while(c>='0'&&c<='9')x=x*10+c-48,c=getchar();return x*flag;13 }14 int meiyong;15 double dp[MAXN][3];16 char s[MAXN];17 int main()18 {19     meiyong=read();20     scanf("%s",s+1);21     int ls=strlen(s+1);22     for(int i=1;i<=ls;i++)23     {24         if(s[i]=='x')    dp[i][1]=dp[i-1][1],dp[i][0]=0;25         if(s[i]=='o')    dp[i][1]=dp[i-1][1]+2*dp[i-1][0]+1,dp[i][0]=dp[i-1][0]+1;26         if(s[i]=='?')    dp[i][1]=(dp[i-1][1]+dp[i-1][1]+2*dp[i-1][0]+1)/2,dp[i][0]=(dp[i-1][0]+1)/2;27     }28     printf("%.4lf",dp[ls][1]);29     return 0;30 }

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.