您的位置:首页 > 理论基础 > 计算机网络

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。
#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  acm-icpc 网络 acm 数学