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

codeforces C. Little Pony and Expected Maximum

时间:2015-03-16 22:32:19      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:

题意:一个筛子有m个面,然后扔n次,求最大值的期望;

思路:最大值为1 有1种,2有2n-1种,  3有3n -2n 种   所以为m的时有mn -(m-1)n 种,所以分别求每一种的概率,然后乘以这个值求和就可以。

技术分享
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <cmath>
 5 #include <algorithm>
 6 using namespace std;
 7 
 8 int n,m;
 9 
10 int main()
11 {
12     cin>>m>>n;
13     double x=pow(1.0/m,n);
14     double ans=x;
15     for(int i=2; i<=m; i++)
16     {
17         double xx=pow(i*1.0/m,n);
18         ans+=(xx-x)*i;
19         x=xx;
20     }
21     printf("%.12lf\n",ans);
22     return 0;
23 }
View Code

 

codeforces C. Little Pony and Expected Maximum

标签:

原文地址:http://www.cnblogs.com/fanminghui/p/4342824.html

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