题解 | #Little Pony and Expected Maximum#
Little Pony and Expected Maximum
https://ac.nowcoder.com/acm/contest/32282/C
【Little Pony and Expected Maximum】
定义为投次,得到最大点数为的概率,但是这个值直接计算比较难。
可以先定义为最大点数小于的概率,则
期望为:
#include <bits/stdc++.h>
using namespace std;
double power(double a, int b) {
double res = 1.0;
while (b) {
if (b & 1) res = res * a;
b >>= 1;
a = a * a;
}
return res;
}
int n, m;
int main() {
cin >> m >> n;
double res = 0;
for (int i = 1; i <= m; i++)
res += i * (power(1.0 * i / m, n) - power(1.0 * (i - 1) / m, n));
printf("%.12lf", res);
return 0;
}