BZOJ 4318: OSU !, Bzoj4318osu
Time Limit: 2 Sec Memory Limit: 128 MB
Submit: 969 Solved: 751
[Submit] [Status] [Discuss] 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 [Submit] [Status] [Discuss]
HOME Back
Consider the contribution of each round of answers to $ (x + 1) ^ 3-x ^ 3 = 3 * x ^ 2 + 3 * x + 1 $
Maintain $ x ^ 2 $, $ x $ respectively
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 double x[MAXN],x2[MAXN],dp[MAXN],p;15 int main()16 {17 int n=read();18 for(int i=1;i<=n;i++)19 {20 scanf("%lf",&p);21 x[i]=(x[i-1]+1)*p;22 x2[i]=(x2[i-1]+2*x[i-1]+1)*p;23 dp[i]=dp[i-1]+(3*x2[i-1]+3*x[i-1]+1)*p;24 }25 printf("%.1lf",dp[n]);26 return 0;27 }