luogu1654 osu!

Source: Internet
Author: User

https://www.zybuluo.com/ysner/note/1300315 Problem surface

There is a total of \ (n\) operations, each operation only success and failure of the points, the success of the corresponding \ (1\), the failure of the corresponding \ (0\),\ (n\) operation corresponds to \ (1\) A \ (01\) string of length \ (n\) .
In this string continuous \ (x\) ( 1\) can contribute to the score of \ (x^3\) , this \ (x\) \ (1\) cannot be other consecutive \ ( 1\) is included.
Now give \ (n\), as well as the success rate of each operation, please output the desired score, the output is rounded and retained \ (1\) decimal place.

    • \ (n\leq10^5\)

      Analytical

      There are so many problems with my sister.
      Think of what would happen if I added another \ (1\) ?
      Contribution will change to \ ((x+1) ^3=x^3+3x^2+3x+1\)
      Actual increase is \ (3x^2+3x+1\)

How can I ask for this thing?
Set \ (x1_i\) indicates the expected length of the \ (1\) string ending with \ (i\) . (Table Increment)
\ (x2_i\) represents the square of the desired length of the \ (1\) string ending with \ (i\) . (Table Increment)
\ (x3_i\) indicates the expected score of the string to \ (i\) . (Cumulative answer)
\ (x1[i]= (x1[i-1]+1) *p\)

The transfer of \ (x_2\) can apply a full square formula:
\ (x2[i]= (x2[i-1]+2*x1[i-1]+1) *p\)

The transfer of F3 is the result of probability multiplication:
\ (x3[i]=x3[i-1]* (1-p) + (x3[i-1]+3*x2[i-1]+3*x1[i-1]+1) *p\)

#include<iostream>#include<cmath>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#define ll long long#define re register#define il inline#define pb(a) push_back(a)#define fp(i,a,b) for(re int i=a;i<=b;i++)#define fq(i,a,b) for(re int i=a;i>=b;i--)using namespace std;const int N=1e5+100;int n;double x1[N],x2[N],x3[N],p;il int gi(){  re int x=0,t=1;  re char ch=getchar();  while(ch!=‘-‘&&(ch<‘0‘||ch>‘9‘)) ch=getchar();  if(ch==‘-‘) t=-1,ch=getchar();  while(ch>=‘0‘&&ch<=‘9‘) x=x*10+ch-48,ch=getchar();  return x*t;}int main(){  n=gi();  fp(i,1,n)    {      scanf("%lf",&p);      x1[i]=(x1[i-1]+1)*p;      x2[i]=(x2[i-1]+2*x1[i-1]+1)*p;      x3[i]=x3[i-1]+(3*x2[i-1]+3*x1[i-1]+1)*p;    }  printf("%.1f\n",x3[n]);  return 0;}

luogu1654 osu!

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.