HDU 4870 rating (probability, expectation, push formula) & zoj 3415 zhou Yu

Source: Internet
Author: User

In fact, zoj 3415 should be called Yu Zhou... After encountering zoj 3415, I used the second method of Reference URL to seek the communication item, and this time I met 4870, I won't do it. After referring to chanme, I re-deduced zhou Yu and the ranking repeatedly (not to push down) four or five times to write this question about plagiarism...

These two questions are very similar. Multi-school rating is equivalent to a forced version, but the principles are the same. It seems that Gaussian yuan can be used for elimination, but I won't. The formula is pushed silently.

Formula Derivation reference http://www.cnblogs.com/chanme/p/3861766.html#2993306

Http://www.cnblogs.com/lijunle/archive/2010/10/09/1846577.html

They are different. Now I feel better at understanding them.

 

HDU 4870 rating

First, consider registering only one account (for the initial E [0], that is, the expectation of 0 to 20, with E [20] = 0)

E [0] = p * E [1] + (1-p) * E [0] + 1 => E [0] = E [1] + 1/P

E [1] = p * E [2] + (1-p) * E [0] + 1 ==> E [0] = E [2] + 1/p + 1/(p * P)

E [2] = p * E [3] + (1-p) * E [0] + 1

E [n-1] = p * E [N] + (1-p) * E [n-3] + 1

E [N] = 0

Obviously, E [0] = E [k] + T [K]. (Because after each input, E [0] and e [k] will be multiplied by the upper coefficient p)

In general, E [k] = p * E [k + 1] + (1-p) * E [K-2] + 1, -T [k] = p * (-T [k + 1]) + (1-p) * (-T [K-2]) + 1

So with T [0] = 0, T [1] = 1/P, T [2] = 1/(p * P) and T [K], T [k + 1], t [K-2], we can find all t [I]

When there are two accounts, this is the result (0, 0) => (1, 0) =>) => .... => (19,19) => (20,19)

T [k] indicates the expected time for an account to reach K from 0, so t [20] + T [19] is the answer.

 

 1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 using namespace std; 5  6 int main(){ 7     double p,t[22]; 8     while(~scanf("%lf",&p)){ 9         t[0]=0,t[1]=1./p,t[2]=1./p+1./(p*p);10         for(int i=3;i<=20;++i) t[i] = (1./p+1./p*t[i-1]-(1-p)/p*t[i-3]);11         printf("%.6lf\n",t[19]+t[20]);12     }13     return 0;14 }
View code

 

Although I think the reference is very, very ...... Very, very, very similar...

 

Zhou Yu, zoj 3415

(The initial E [N], that is, the expectation of N to 0, with E [0] = 0)

Similar Method, do not want to play the derivation process...

 1 #include <cstdio> 2 #include <iostream> 3 using namespace std; 4  5 double pp(double a,int n){ 6     double ret=1; 7     while(n){ 8         if(n&1) ret *= a; 9         a*=a;10         n>>=1;11     }12     return ret;13 }14  int main(){15      int n,m;16      while(~scanf("%d%d",&n,&m)){17          if(m==2){printf("%.10lf\n",1.*n*(n+1));continue;}18          double ans = 1.*m/(m-2)/(m-2);19          double tmp = pp(1./(m-1),n) + 1.*n*(m-2) - 1;20          printf("%.10lf\n",ans*tmp);21      }22      return 0;23  }
View code

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.