jzoj3801-[NOIP2014模拟8.23]骰子【数学期望】
生活随笔
收集整理的这篇文章主要介绍了
jzoj3801-[NOIP2014模拟8.23]骰子【数学期望】
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
正题
题目链接:https://jzoj.net/senior/#main/show/3801
题目大意
mmm面的骰子是1∼m1\sim m1∼m,然后丢nnn次,求最大值的数学期望。
解题思路
若抛到的数都≤i\leq i≤i那么期望概率就是(1i)n(\frac{1}{i})^n(i1)n
我们考虑若iii是最大值时概率就是(1i)n−(1i−1)n(\frac{1}{i})^n-(\frac{1}{i-1})^n(i1)n−(i−11)n,然后枚举加快速幂即可
时间复杂度O(mlogn)O(m\log n)O(mlogn)
codecodecode
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; double pow(double x,int b) {double ans=1;while(b){if(b&1) ans=ans*x;x=x*x;b>>=1;}return ans; } int n; double m,ans; int main() {scanf("%lf%d",&m,&n);ans+=pow(1.0/m,n);for(double i=2;i<=m;i++)ans+=i*(pow(i/m,n)-pow((i-1.0)/m,n));printf("%.10lf",ans); }总结
以上是生活随笔为你收集整理的jzoj3801-[NOIP2014模拟8.23]骰子【数学期望】的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 诺基亚 G42 5G 手机已开始测试安卓
- 下一篇: 牛客-Forsaken喜欢独一无二的树【