Codeforces round #259 (Div. 2) c-little pony and expected maximum (mathematical expectation)

Source: Internet
Author: User

Question Link

Question: I threw a dice on the m Plane n times and expected the maximum value.

Idea: mathematical expectation. The formula for discretization is E (x) = x1 * P (X1) + x2 * P (X2) + ...... + Xn * P (Xn)

P (xi) indicates the number of all cases where the maximum value is XI/The total number of cases is m ^ N, throwing n times, the number of all cases where the maximum value is XI should be Xi ^ N, but the maximum value is not XI and cannot exceed Xi, so subtract the maximum value is a XI-1 or the maximum value does not exceed this number of cases. That is, sum + = xi * (Xi ^ N-(XI-1) ^ N)/m ^ N, but this is certainly not good, because the value range of M n is 10 ^ 5, 100000 ^ 100000 will overflow and the M ^ N in this formula will be mentioned in brackets, that is, sum + = xi * (XI/m) ^ N-(XI-1)/m) ^ N ).

 1 //C. Little Pony and Expected Maximum 2 #include <cstdio> 3 #include <cstring> 4 #include <iostream> 5 #include <cmath> 6  7 using namespace std ; 8  9 int main()10 {11     double m , n ;12     while(~scanf("%lf %lf",&m,&n))13     {14         double sum = 0.0;15         for(int i = 1 ; i <= m ; i++)16         {17             sum += (pow(i/m,n)-pow((i-1)/m,n))*i ;18         }19         printf("%.12lf\n",sum) ;20     }21     return 0 ;22 }
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.