zoukankan      html  css  js  c++  java
  • LG5104 红包发红包 概率与期望

    问题描述

    LG5104


    题解

    观察发现,对于 (w) ,期望得钱是 (frac{w}{2})

    然后答案就是 (frac{w}{2^k})

    然后快速幂求个逆元就好了。


    (mathrm{Code})

    #include<bits/stdc++.h>
    using namespace std;
    
    #define int long long
    
    const int mod=1000000007;
    
    template <typename Tp>
    void read(Tp &x){
    	x=0;char ch=1;int fh;
    	while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    	if(ch=='-'){
    		fh=-1;ch=getchar();
    	}
    	else fh=1;
    	while(ch>='0'&&ch<='9'){
    		x=(x<<1)+(x<<3)+ch-'0';
    		ch=getchar();
    	}
    	x*=fh;
    }
    
    int n,w,k;
    
    int ksm(int x,int p){
    	int res=1;
    	while(p){
    		if(p&1) res=res*x%mod;
    		p>>=1;x=x*x%mod;
    	}
    	return res;
    }
    
    signed main(){
    	read(w);read(n);read(k);
    	printf("%lld
    ",(w*(ksm(ksm(2,k)%mod,mod-2)%mod))%mod);
    	return 0;
    }
    
  • 相关阅读:
    随机生成300道四则运算
    练习
    电梯演说模板练习
    敏捷开发
    团队模式
    思考
    build to win 观后感
    四则运算
    Code review
    Mutual review
  • 原文地址:https://www.cnblogs.com/liubainian/p/11638640.html
Copyright © 2011-2022 走看看