BZOJ5091摘苹果(概率、期望)
生活随笔
收集整理的這篇文章主要介紹了
BZOJ5091摘苹果(概率、期望)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目:https://www.lydsy.com/JudgeOnline/problem.php?id=5091
題目告訴我們,初始選每一個點的概率為di/2m,那么走一次到達某個點u的概率為
這不是和初始選點的概率一樣了么。。。。結束。。。。
代碼:
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 using namespace std; 5 6 typedef long long LL; 7 const LL p = (LL)1e9 + 7; 8 LL n, m, k, E; 9 LL arr[100005], degree[100005]; 10 11 void exGCD(LL a, LL b, LL &d, LL &x, LL &y) 12 { 13 if(!b) d = a, x = 1, y = 0; 14 else 15 { 16 exGCD(b, a % b, d, y, x); 17 y -= a / b * x; 18 } 19 } 20 LL Inverse(LL _x) 21 { 22 LL d, x, y; 23 exGCD(_x, p, d, x, y); 24 if(x < 0) x += p; 25 return x; 26 } 27 int main() 28 { 29 scanf("%lld%lld%lld", &n, &m, &k); 30 for(LL i = 1; i <= n; i++) 31 scanf("%lld", arr + i); 32 for(LL i = 0; i < m; i++) 33 { 34 LL x, y; 35 scanf("%lld%lld", &x, &y); 36 degree[x]++, degree[y]++; 37 } 38 for(LL i = 1; i <= n; i++) 39 E = (E + degree[i] * arr[i]) % p; 40 printf("%lld\n", E * k % p * Inverse(m * 2) % p); 41 42 return 0; 43 }//Rhein_E View Code轉載于:https://www.cnblogs.com/Rhein-E/p/9390451.html
總結
以上是生活随笔為你收集整理的BZOJ5091摘苹果(概率、期望)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 橱窗布置
- 下一篇: git与eclipse集成之代码冲突与解