您的位置:首页 > 其它

【CF 453A】 A. Little Pony and Expected Maximum(期望、快速幂)

2017-04-21 19:44 501 查看
A. Little Pony and Expected Maximum

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.

The dice has m faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the m-th face contains mdots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability

1 #include<cstdio>
2 #include<cstdlib>
3 #include<cstring>
4 #include<iostream>
5 #include<algorithm>
6 #include<cmath>
7 using namespace std;
8 #define Maxn 100010
9
10 double qpow(double x,int b)
11 {
12     double ans=1;
13     while(b)
14     {
15         if(b&1) ans=ans*x;
16         x=x*x;
17         b>>=1;
18     }
19     return ans;
20 }
21
22 int main()
23 {
24     int m,n;
25     scanf("%d%d",&m,&n);
26     double ans=0;
27     for(int i=1;i<=m;i++)
28     {
29         ans+=i*(qpow(1.0*i/m,n)-qpow(1.0*(i-1)/m,n));
30     }
31     printf("%.5lf\n",ans);
32     return 0;
33 }


View Code

2017-04-21 19:44:52
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: