zoukankan      html  css  js  c++  java
  • P5104 红包发红包 连续性概率

    P5104 红包发红包 连续性概率

    链接

    我们先考虑第一次抽红包。

    显然,抽的钱数在 ((0,k]) 之间的概率是 (frac k w),再根据概率密度函数是概率分布函数的导数,我们可以求得概率密度函数为:

    [f(x)=egin{cases} frac 1 w &(0le xle w)\ 0&x< 0,x>w end{cases} ]

    所以我们积分一下不难得出抽一次的期望:

    [E_1=int_{i=0}^w xf(x)=frac w 2 ]

    我们现在考虑抽第二次。这里假设第一次抽取的钱为 (a) ,那么第二次抽钱期望抽到 (frac{w-a}2)

    那么抽第二次的期望就应该是:

    [E_2=int_{i=0}^w frac{w-a}2f(a)=frac{w}4 ]

    对于第三次,我们可以把前两次的抽取看做一次,具体来说,就设这个概率密度函数为 (g) ,虽然我们不知道 (g) 具体是什么,但是我们知道:

    [E_2=int _{i=0}^w xg(x)=frac{w}{4} ]

    如此下去,可以得到第 (k) 次抽钱的期望是 (frac{w}{2^k})

    打一个快速幂就过去了。

    #include<bits/stdc++.h>
    #define dd double
    #define ld long double
    #define ll long long
    #define uint unsigned int
    #define ull unsigned long long
    #define N number
    #define M number
    using namespace std;
    
    const int INF=0x3f3f3f3f;
    const ll mod=1e9+7;
    
    template<typename T> inline void read(T &x) {
        x=0; int f=1;
        char c=getchar();
        for(;!isdigit(c);c=getchar()) if(c == '-') f=-f;
        for(;isdigit(c);c=getchar()) x=x*10+c-'0';
        x*=f;
    }
    
    inline ll ksm(ll a,ll b,ll mod){
        ll res=1;
        while(b){
            if(b&1) (res*=a)%=mod;
            a=a*a%mod;
            b>>=1;
        }
        return res;
    }
    
    int main(){
        ll w,n,k;read(w);read(n);read(k);
        ll inv=ksm(2,mod-2,mod);
        ll nowinv=ksm(inv,k,mod);
        printf("%lld
    ",w*nowinv%mod);
        return 0;
    }
    
  • 相关阅读:
    LeetCode 876. 链表的中间结点
    顺序表的定义及其相关基本操作
    LeetCode 206. 反转链表
    LeetCode 111. 二叉树的最小深度
    LeetCode 700. 二叉搜索树中的搜索
    LeetCode 104. 二叉树的最大深度
    LeetCode 908. 最小差值 I
    LeetCode 728. 自除数
    LeetCode 704. 二分查找
    LeetCode 852. 山脉数组的峰顶索引 (二分)
  • 原文地址:https://www.cnblogs.com/TianMeng-hyl/p/14984877.html
Copyright © 2011-2022 走看看