码迷,mamicode.com
首页 > 其他好文 > 详细

(寒假CF3)坑坑坑

时间:2015-02-03 21:14:52      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

题意 :求期望

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

坑点:要简化,不简化数字一大就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 }

 

(寒假CF3)坑坑坑

标签:

原文地址:http://www.cnblogs.com/awsent/p/4270983.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!