(寒假CF3)坑坑坑

题意 :求期望

题解 :找规律,列举几个,然后找到规律。

坑点:要简化,不简化数字一大就wa了

 

 

Sample Input
Input
6 1
Output
3.500000000000
Input
6 3
Output
4.958333333333
Input
2 2
Output
1.750000000000
Hint
Consider the third test example. If you've made two tosses:

You can get 1 in the first toss, and 2 in the second. Maximum equals to 2.
You can get 1 in the first toss, and 1 in the second. Maximum equals to 1.
You can get 2 in the first toss, and 1 in the second. Maximum equals to 2.
You can get 2 in the first toss, and 2 in the second. Maximum equals to 2.
The probability of each outcome is 0.25, that is expectation equals to:


You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value

 

 1 #include<stdio.h>
 2 #include<math.h>
 3 int main()
 4 {
 5     int m,n,times,i,j,a;
 6     float sum;
 7     while(~scanf("%d %d",&m,&n))
 8     {
 9         sum=0.0;
10 
11                 for(j=1;j<=m;j++)
12             {
13                 sum+=(pow(1.0*j/m,n)-pow(1.0*(j-1)/m,n))*j;
14             }
15         printf("%.12lf\n",sum);
16     }
17     return 0;
18 }

 

posted @ 2015-02-03 20:25  江豚  阅读(108)  评论(0编辑  收藏  举报