Coin 2017ICPC西安网络赛
2018-04-10 04:38
197 查看
原题链接:https://nanti.jisuanke.com/t/17115
Bob has a not even coin, every time he tosses the coin, the probability that the coin's front face up is \frac{q}{p}(\frac{q}{p}
\le \frac{1}{2})pq(pq≤21).
The question is, when Bob tosses the coin kk times,
what's the probability that the frequency of the coin facing up is even number.
If the answer is \frac{X}{Y}YX,
because the answer could be extremely large, you only need to print (X
* Y^{-1}) \mod (10^9+7)(X∗Y−1)mod(109+7).
indicates the number of test cases (T
\le 100T≤100).
Then Each line has 33 integer p,q,k(1\le
p,q,k \le 10^7)p,q,k(1≤p,q,k≤107) indicates
the i-th test case.
题意:一枚不均匀的硬币,正面朝上的概率为q/p,这枚硬币抛了k次,求正面朝上的次数是偶数次的概率mod 10000000007
思路:由二项分布公式可以计算正面朝上是偶数次的概率,但是直接用二项分布公式不好写,而且会超时。我们可以将二项分布公式用二项式定理表示,对二项式进行化简。
二项式为:([ (q/p+1-q/p)^n+(q/p-(1-q/p))^n]/2)%mod
化简为[1+(p-2q)^n*(p^n)^(mod-2)%mod]*2^(mod-2)%mod;
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
ll p,q,k;
ll pow_m(ll x,ll y)
{
ll ret=1,t=x%mod;
while(y)
{
if(y&1)
{
ret*=t;
ret%=mod;
}
y>>=1;
t*=t;
t%=mod;
}
return ret;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld%lld",&p,&q,&k);
ll ans=1+pow_m(p-2*q,k)*pow_m(pow_m(p,k),mod-2);
//printf("%lld\n",ans);
ans=ans%mod;
ans=ans*pow_m(2,mod-2);
ans%=mod;
printf("%lld\n",ans);
}
}
Bob has a not even coin, every time he tosses the coin, the probability that the coin's front face up is \frac{q}{p}(\frac{q}{p}
\le \frac{1}{2})pq(pq≤21).
The question is, when Bob tosses the coin kk times,
what's the probability that the frequency of the coin facing up is even number.
If the answer is \frac{X}{Y}YX,
because the answer could be extremely large, you only need to print (X
* Y^{-1}) \mod (10^9+7)(X∗Y−1)mod(109+7).
Input Format
First line an integer TT,indicates the number of test cases (T
\le 100T≤100).
Then Each line has 33 integer p,q,k(1\le
p,q,k \le 10^7)p,q,k(1≤p,q,k≤107) 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
题意:一枚不均匀的硬币,正面朝上的概率为q/p,这枚硬币抛了k次,求正面朝上的次数是偶数次的概率mod 10000000007
思路:由二项分布公式可以计算正面朝上是偶数次的概率,但是直接用二项分布公式不好写,而且会超时。我们可以将二项分布公式用二项式定理表示,对二项式进行化简。
二项式为:([ (q/p+1-q/p)^n+(q/p-(1-q/p))^n]/2)%mod
化简为[1+(p-2q)^n*(p^n)^(mod-2)%mod]*2^(mod-2)%mod;
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
ll p,q,k;
ll pow_m(ll x,ll y)
{
ll ret=1,t=x%mod;
while(y)
{
if(y&1)
{
ret*=t;
ret%=mod;
}
y>>=1;
t*=t;
t%=mod;
}
return ret;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld%lld",&p,&q,&k);
ll ans=1+pow_m(p-2*q,k)*pow_m(pow_m(p,k),mod-2);
//printf("%lld\n",ans);
ans=ans%mod;
ans=ans*pow_m(2,mod-2);
ans%=mod;
printf("%lld\n",ans);
}
}
相关文章推荐
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B. Coin
- 计蒜客 17115 2017 ICPC 西安网络赛 B Coin
- 计蒜客 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B coin(求乘法逆元)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B.Coin(数学推公式)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Coin
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B Coin(逆元,费马小定理)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B Coin (概率计算)
- 4000 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B. Coin
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B.Coin(基本概率+二项式展开)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B. Coin
- 【二项式定理】【推导】计蒜客17115 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B. Coin
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B. Coin(概率)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Coin 概率+矩阵快速幂
- 【2017 ACM-ICPC 亚洲区(西安赛区)网络赛】 B. Coin
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B coin
- B. Coin 数学/组合数 2017 ACM-ICPC 亚洲区(西安赛区)网络赛
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 - Coin(二项式展开)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Coin (概率公式+快速幂)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B Coin (概率计算)
- 计蒜客17115 Coin 数学 2017 ACM-ICPC 亚洲区(西安赛区)网络赛