2017 ACM-ICPC 亚洲区(西安赛区)网络赛: B. Coin 概率题
Posted ╰追憶似水年華ぃ╮
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2017 ACM-ICPC 亚洲区(西安赛区)网络赛: B. Coin 概率题相关的知识,希望对你有一定的参考价值。
Bob has a not even coin(就是一个不均匀的硬币,朝上的概率不一定是1/2), every time he tosses the coin, the probability that the coin\'s front face up is q/p(q/p<=1/2).
The question is, when Bob tosses the coin k times, what\'s the probability that the frequency of the coin facing up is even number(就是硬币朝上次数为偶数次的概率和,0次也算).
If the answer is X/Y, because the answer could be extremely large, you only need to print (X * Y^{-1}) /mod (10^9+7).
Input Format
First line an integer TT, indicates the number of test cases (T≤100).
Then Each line has 33 integer p,q,k(1<= p,q,k ,k<=10^7) indicates the i-th test case.
Output Format
For each test case, print an integer in a single line indicates the answer.
样例输入
2
2 1 1
3 1 2
样例输出
500000004
555555560
思路:
题目说的有点晦涩。
一个组合数学题。。。。。
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 const int MOD=1e9+7; 7 typedef long long ll; 8 ll p,q,k; 9 10 ll qmod(ll x,ll n) 11 { 12 ll res=1; 13 while(n){ 14 if(n&1) res=(res*x)%MOD; 15 x=(x*x)%MOD; 16 n/=2; 17 } 18 return res; 19 } 20 21 int main() 22 { 23 int T; 24 cin>>T; 25 while(T--) 26 { 27 cin>>p>>q>>k; 28 ll x=qmod(p,k); 29 ll y=qmod(p-2*q,k); 30 ll ans=((x+y)%MOD*qmod(2*x,MOD-2))%MOD; 31 cout<<ans<<endl; 32 } 33 return 0; 34 }
以上是关于2017 ACM-ICPC 亚洲区(西安赛区)网络赛: B. Coin 概率题的主要内容,如果未能解决你的问题,请参考以下文章
2017 ACM-ICPC 亚洲区(西安赛区)网络赛: B. Coin 概率题
2017 ACM-ICPC 亚洲区(西安赛区)网络赛 G. Xor
2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B.Coin(基本概率+二项式展开)
2017 ACM-ICPC 亚洲区(西安赛区)网络赛 F.Trig Function(论文+组合数)