发红包
题型描述
连续型变量期望
题目描述&数据范围
题解
注意到 $x$ 是实数,所以应用连续型变量的期望公式: $\int_{-\infty}^{\infty}xf(x)dx $
其中
$$
f(x)=
\begin{cases}
\frac{1}{w},0<=x<=w\
0,x<0 || x>w
\end{cases}
$$
设第 $i$ 个人的期望是 $E(i)$
第 $1$ 个人抢红包时还剩下 $w$ 元,所以积分范围是 $[0,w]$ ,解得 $E(1)=\frac{w}{2}$
第 $2$ 个人抢红包时期望还剩下 $w-\frac{w}{2}=\frac{w}{2}$ 元,所以积分范围是 $[0,\frac{w}{2}]$ ,解得 $E(2)=\frac{w}{4}$
以此类推,第 $k$ 个人抢红包的期望是 $E(2)=\frac{w}{2^K}$
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1000000;
const int mod=1e9+7;
ll qpow(ll a,ll x){
ll res=1;
while(x){
if(x&1)res=res*a%mod;
a=a*a%mod;
x>>=1;
}
return res%mod;
}
void solve(){
ll n,m,k;
cin>>n>>m>>k;
ll ans=n*qpow(qpow(2,k),mod-2);
cout<<ans%mod<<'\n';
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//fstream in("in.txt",ios::in);cin.rdbuf(in.rdbuf());
int t=1;//cin>>t;
while(t--)solve();
return 0;
}