BZOJ 4318: OSU !, Bzoj4318osu

Source: Internet
Author: User

BZOJ 4318: OSU !, Bzoj4318osu
Descriptionosu is a casual software popular with the masses. We can simplify and adapt osu rules to the following: there are a total of n operations, each operation can only be successful or failed, the success corresponds to 1, the Failure Corresponds to 0, n operations correspond to 1 01 string with a length of n. The continuous X 1 in this string can contribute the X ^ 3 score, which cannot be included by other consecutive 1 (that is, a very long string of 1, for details, see the example below.) Now we provide n and the success rate of each operation. Please output the expected score, and the output will be rounded to one decimal place.

 

The first line of Input has a positive integer n, indicating the number of operations. The next n rows have a real number between 0 and 1, indicating the success rate of each operation.

 

Output has only one real number, indicating the answer. The answer is rounded to one decimal place.

 

Sample Input3
0.5
0.5
0.5 Sample Output6.0
HINT

 

[Example]
0,001 score: 1,010 score: 1,100 score: 1,101 score: 2,110 score: 8,011 score: 8,111 score: 48/8 score: 27, total: 48, expected to be 6.0 =
N <= 100000

 

 

Source

 

Consider recursion, use the cubic difference formula for transfer, and maintain E (x ^ 3), E (x ^ 2), E (x), E (1 ).

 

Consider the I operation. Set the maximum length of 1 at the end of the operation to x.

(1) If the operation fails, the contribution is 0;

(2) If the operation succeeds, the contribution is (x + 1) ^ 3-x ^ 3.

The expected value is (1-pi) * 0 + pi * (x + 1) ^ 3-x ^ 3 ).

The simplified answer is pi * (x + 1) ^ 3-x ^ 3 ).

Note that we do not know what x ^ 3 is, but we can calculate the expected value of x ^ 3. Based on the expected value, we know that this is the expected result.

 

Suppose we already know how E (x ^ 3) calculates E (x + 1) ^ 3 )? Consider recursion.

E (x ^ 3) = 0 ^ 3 * P (x = 0) + 1 ^ 3 * P (x = 1) +... + maxl ^ 3 * P (x = maxl)

E (x + 1) ^ 3) = 1 ^ 3 * P (x = 0) + 2 ^ 3 * P (x = 1) +... + (maxl + 1) ^ 3 * P (x = maxl)

Expand the second formula with the binary theorem, and then bring the first formula into it.

E (x + 1) ^ 3) = E (x ^ 3) + 3E (x ^ 2) + 3E (x) + E (1 ).

We can also recursively maintain E (x ^ 2), E (x), and E (1.

 

 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 #include<vector> 7 using namespace std; 8 const int MAXN=100001; 9 const int maxn=0x7fffff;10 void read(int &n)11 {12     char c='+';int x=0;bool flag=0;13     while(c<'0'||c>'9')14     {c=getchar();if(c=='-')flag=1;}15     while(c>='0'&&c<='9')16     {x=x*10+c-48;c=getchar();}17     flag==1?n=-x:n=x;18 }19 double f[MAXN],g[MAXN],dp[MAXN];20 int main()21 {22     int n;23     read(n);24     for(int i=1;i<=n;i++)25     {26         double now;27         scanf("%lf",&now);28         f[i]=now*(f[i-1]+1);29         g[i]=now*(g[i-1]+f[i-1]*2+1);30         dp[i]=dp[i-1]+now*(g[i-1]*3+f[i-1]*3+1);31     }32     printf("%.1lf",dp[n]);33     return 0;34 }

 

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.