Luo Gu P5104 red envelopes red envelopes

Topic links:

P5104

Topic analysis:

Title and \ (n \) is no relationship, because it is \ (n \) people are competing, in fact, is not necessarily finished grab

In fact, it is clear ...... we would expect to find a continuous random variable is
first set up a random variable \ (the X-\) , represents the first person to get the money, then there is the distribution function \ (F (x) = \ frac {x - a} {b - a}
= \ frac {x - 0} {w - 0} = \ frac {x} {w} \) then the distribution function evaluation a guide, a density function \ (f (x) = \ lim _ {\ Delta x \ to 0} \ frac {\ frac {x + \ Delta x} {w} - \ frac {x} {w}} {\ Delta x} = \ frac {1} {w} \ )
the continuous random variable desired definition, \ (E = \ the int_ {0} ^ {W} XF (X) DX \) , count found \ (\ FRAC {W} {2} \) , then almost, every time the recursive \ (W \) into \ (\ frac {w} { 2} \)

Code:

#include <bits/stdc++.h>
#define int long long 
using namespace std;
inline int read() {
    int cnt = 0, f = 1; char c = getchar();
    while (!isdigit(c)) {if (c == '-') f = -f; c = getchar();}
    while (isdigit(c)) {cnt = (cnt << 3) + (cnt << 1) + c - '0'; c = getchar();}
    return cnt * f;
}
int w, n, k;
const int p = (1000000000 + 7);
int ksm(int a, int b, int mod) {
    long long res = 1;
    while (b) {
        if (b & 1) res = (res * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res % mod;
}
signed main() {
    w = read(), n = read(), k = read();
    int inv = ksm(2, k, p);
    int ans = w * ksm(inv, p - 2, p) % p;
    printf("%lld", ans % p);
    return 0;
}

Guess you like

Origin www.cnblogs.com/kma093/p/11345692.html