4000 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B. Coin
2017-09-16 19:49
363 查看
题意:已知正面朝上概率为b/a,求抛k次硬币,正面朝上次数为偶数的概率。
思路:
所求即为sigma[C(i, n)*p^i*(1-p)^(n-i)] (i为偶数的和)。
由二项式定理,全部项的和为sum1 = (x+y)^n, 令y' = -y, sum2 = (x-y)^n。
对应到此题即为 [(b/a-(1-b/a))^n + 1] / 2。
思路:
所求即为sigma[C(i, n)*p^i*(1-p)^(n-i)] (i为偶数的和)。
由二项式定理,全部项的和为sum1 = (x+y)^n, 令y' = -y, sum2 = (x-y)^n。
对应到此题即为 [(b/a-(1-b/a))^n + 1] / 2。
#include <iostream> #include <string> #include <vector> #include <stack> #include <queue> #include <deque> #include <set> #include <map> #include <algorithm> #include <functional> #include <utility> #include <cstring> #include <cstdio> #include <cstdlib> #include <ctime> #include <cmath> #include <cctype> #define CLEAR(a, b) memset(a, b, sizeof(a)) #define IN() freopen("in.txt", "r", stdin) #define OUT() freopen("out.txt", "w", stdout) #define LL long long #define maxn 10000005 #define maxm 100005 #define mod 1000000007 #define INF 1000000007 #define EPS 1e-7 #define PI 3.1415926535898 #define N 26 using namespace std; //-------------------------CHC------------------------------// LL qpow(LL a, LL b) { int ret = 1; while (b) { if (b & 1) ret = ret * a %mod; a = a*a%mod; b >>= 1; } return ret; } int main() { int T; cin >> T; while (T--) { int a, b, k; cin >> a >> b >> k; LL ans = (qpow(a - 2 * b, k)*qpow(qpow(a, k), mod - 2)%mod + 1)*qpow(2, mod - 2)%mod; cout << ans << endl; } return 0; }
相关文章推荐
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B coin
- 【2017 ACM-ICPC 亚洲区(西安赛区)网络赛】 B. Coin
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛_Coin
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Coin (概率公式+快速幂)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B Coin(逆元,费马小定理)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B Coin (概率计算)
- 计蒜客17115 Coin 数学 2017 ACM-ICPC 亚洲区(西安赛区)网络赛
- 计蒜客 17115 Coin(2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B:coin
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛: B. Coin
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B. Coin
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B. Coin(矩阵快速幂)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Coin 二项式定理
- B. Coin 数学/组合数 2017 ACM-ICPC 亚洲区(西安赛区)网络赛
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B.Coin(数学推公式)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛b题Coin(矩阵快速幂)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B题 coin
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B. Coin(构造二项式定理 or dp矩阵优化)
- Coin (2017 ACM-ICPC 亚洲区(西安赛区)网络赛B题)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B. Coin