Luogu5104 红包发红包 (期望)

曾几何时有人说概率期望easy。。。

显然,期望是(frac{w}{2^n})

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int  a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int  a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long

#define ON_DEBUG

#ifdef ON_DEBUG

#define D_e_Line printf("

----------

")
#define D_e(x)  cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt","r",stdin);

#else

#define D_e_Line ;
#define D_e(x)  ;
#define Pause() ;
#define FileOpen() ;

#endif

struct ios{
    template<typename ATP>ios& operator >> (ATP &x){
        x = 0; int f = 1; char c;
        for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-')  f = -1;
        while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
        x*= f;
        return *this;
    }
}io;
using namespace std;

const int mod = 1e9 + 7; 

inline long long Pow(long long a, long long b){
	long long s = 1;
	while(b){
		if(b & 1) s = s * a % mod;
		a = a * a % mod, b >>= 1; 
	}
	return s;
}
int main(){
	long long n, xxx, w;
	io >> w >> xxx >> n;
	
	printf("%lld", w * Pow(Pow(2, n), mod - 2) % mod);
	
	return 0;
}

原文地址:https://www.cnblogs.com/bingoyes/p/11244576.html