题解 | #Little Pony and Expected Maximum#

Little Pony and Expected Maximum

https://ac.nowcoder.com/acm/contest/32282/C

【Little Pony and Expected Maximum】

定义P(Y=y)P(Y=y)为投nn次,得到最大点数为yy的概率,但是这个值直接计算比较难。

可以先定义P(Yy)P(Y\le y)为最大点数小于yy的概率,则P(Y=y)=P(Yy)P(Yy1)P(Y=y)=P(Y\le y)-P(Y\le y-1)

P(Yy)=P(x1y,x2y,...,xny)=P(Xy)n=(ym)n\begin{matrix} P(Y\le y)&=&P(x_1\le y,x_2\le y,...,x_n\le y) \\ \\ &=&P(X\le y)^n \\ \\ &=&(\frac{y}{m})^n \end{matrix}

期望为:

E[Y]=y=1myP(Y=y)=y=1my[(ym)n(y1m)n]\mathbb{E}[Y]=\sum_{y=1}^my\cdot P(Y=y)=\sum_{y=1}^my\cdot [ (\frac{y}{m})^n-(\frac{y-1}{m})^n ]
#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;
}
全部评论

相关推荐

大疆在线测评都考什么呀,会考企业概况啥的吗
又被画饼了的做题家很...:不会。刚做完,就是材料分析、态度题、算术题、逻辑题。总共60道。
投递大疆等公司7个岗位
点赞 评论 收藏
分享
废物一个0offer:认真的吗二本本科找人工智能岗位
点赞 评论 收藏
分享
05-29 22:11
门头沟学院 Java
Elastic90:抛开学历造假不谈,这公司的招聘需求也挺怪的,Java开发还要求你有图文识别、移动端开发和c++的经验,有点逆天了。
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-11 17:10
什么素质,我请问呢,要掉小珍珠了。。。又憋屈又生气
苍蓝星上艾露:给它们能的,一群dinner牛马挥刀向更弱者罢了。我写的开源求职AI co-pilot工具,优化你的简历,找到你匹配的岗位,定制你的简历,并让你做好面试准备https://github.com/weicanie/prisma-ai
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务