B. Coin 数学/组合数 2017 ACM-ICPC 亚洲区(西安赛区)网络赛
来源:互联网 发布:淘宝助手 mac版下载 编辑:程序博客网 时间:2024/06/03 04:38
Bob has a not even coin, every time he tosses the coin, the probability that the coin's front face up is pq(pq≤21).
The question is, when Bob tosses the coin ktimes, what's the probability that the frequency of the coin facing up is even number.
If the answer is YX, because the answer could be extremely large, you only need to print (X∗Y−1)mod(109+7).
Bob has a not even coin, every time he tosses the coin, the probability that the coin's front face up is pq(pq≤21).
The question is, when Bob tosses the coin ktimes, what's the probability that the frequency of the coin facing up is even number.
If the answer is YX, because the answer could be extremely large, you only need to print (X∗Y−1)mod(109+7).
Input Format
First line an integer T, indicates the number of test cases (T≤100).
Then Each line has 3 integer p,q,k(1≤p,q,k≤107) indicates the i-th test case.
First line an integer T, indicates the number of test cases (T≤100).
Then Each line has 3 integer 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.
For each test case, print an integer in a single line indicates the answer.
样例输入
22 1 13 1 2
22 1 13 1 2
样例输出
500000004555555560
题目题意:题目给了一种特殊的硬币,其中正面朝上的概率是q/p,我们丢硬币k次,问硬币朝上的次数是偶数的概率为多少 (要 mod 1e9+7)
题目分析:根据题目题意不难推出答案为
C (k,a)*(q/p)^a*(1-q/p)^(k-a) mod 1e9+7 (其中a是0 2 4 ..这些偶数)
这里我们先用一个公式
发现我们的答案和这个式子有点像,只是一个遍历所有的数(0到n) 一个是(0,2,4都是偶数)
怎么办了?
我们来看一下下面例子:
a1+a2+a3+a4+a5+...+an
假如我们要求a1+a3+a5+.....
只要我们知道 a1-a2+a3-a4+a5-a6+..-..
那么答案就是原式加上它除以2
现在我们知道原始了,其中p=(q/p),q=(1-q/p)
那么p+q=1
不难发现我们只需要将p令为-p展开就可以得到了
那么即(-p+q)=(p-2*q)/p
那么答案即为
然后就可以算了,费马小定理求逆元
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#define ll long longusing namespace std;const ll mod=1e9+7;ll fast_pow(ll base,ll k){ ll ans=1; while (k) { if (k&1) ans=ans*base%mod; base=base*base%mod; k>>=1; } return ans;}int main(){ int t; scanf("%d",&t); while (t--) { ll p,q,k; scanf("%lld%lld%lld",&p,&q,&k); ll ans=(p-2*q)*fast_pow(p,mod-2)%mod; ans=fast_pow(ans,k); ans=ans+1; ans=(ans%mod+mod)%mod;//注意这里处理一下,避免为负数 ans=ans%mod*fast_pow(2,mod-2)%mod; printf("%lld\n",ans); } return 0;}
500000004555555560
题目题意:题目给了一种特殊的硬币,其中正面朝上的概率是q/p,我们丢硬币k次,问硬币朝上的次数是偶数的概率为多少 (要 mod 1e9+7)
题目分析:根据题目题意不难推出答案为
C (k,a)*(q/p)^a*(1-q/p)^(k-a) mod 1e9+7 (其中a是0 2 4 ..这些偶数)
这里我们先用一个公式
发现我们的答案和这个式子有点像,只是一个遍历所有的数(0到n) 一个是(0,2,4都是偶数)
怎么办了?
我们来看一下下面例子:
a1+a2+a3+a4+a5+...+an
假如我们要求a1+a3+a5+.....
只要我们知道 a1-a2+a3-a4+a5-a6+..-..
那么答案就是原式加上它除以2
现在我们知道原始了,其中p=(q/p),q=(1-q/p)
那么p+q=1
不难发现我们只需要将p令为-p展开就可以得到了
那么即(-p+q)=(p-2*q)/p
那么答案即为
然后就可以算了,费马小定理求逆元
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#define ll long longusing namespace std;const ll mod=1e9+7;ll fast_pow(ll base,ll k){ ll ans=1; while (k) { if (k&1) ans=ans*base%mod; base=base*base%mod; k>>=1; } return ans;}int main(){ int t; scanf("%d",&t); while (t--) { ll p,q,k; scanf("%lld%lld%lld",&p,&q,&k); ll ans=(p-2*q)*fast_pow(p,mod-2)%mod; ans=fast_pow(ans,k); ans=ans+1; ans=(ans%mod+mod)%mod;//注意这里处理一下,避免为负数 ans=ans%mod*fast_pow(2,mod-2)%mod; printf("%lld\n",ans); } return 0;}
- B. Coin 数学/组合数 2017 ACM-ICPC 亚洲区(西安赛区)网络赛
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B.Coin(数学推公式)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Coin(组合数)
- 计蒜客-2017 ACM-ICPC 亚洲区(西安赛区)网络赛E题Coin(概率、组合数学)
- 计蒜客17115 Coin 数学 2017 ACM-ICPC 亚洲区(西安赛区)网络赛
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B. Coin(概率)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B Coin (概率计算)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B. Coin(矩阵快速幂)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B Coin (概率计算)
- 计蒜客 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 亚洲区(西安赛区)网络赛: B. Coin
- Coin (2017 ACM-ICPC 亚洲区(西安赛区)网络赛B题)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B. Coin
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B.Coin(基本概率+二项式展开)
- 3.定义一个接受两个数字的方法,返回两个数字的和 →(javascript代返回值的函数的申明和调用)
- VS2017安装过程电脑突然关机
- 文章标题
- Java学习4:构造函数
- 第二周-项目2
- B. Coin 数学/组合数 2017 ACM-ICPC 亚洲区(西安赛区)网络赛
- git&github 使用git将本地项目push到github
- Ubantu16.04下创建matlab启动快捷键
- 通俗的方式理解RxJS
- Spark2.x学习笔记:9、 Spark编程实例
- pandas read data from files
- CentOS 6.5 yum安装MongoDb
- Spring 动态代理(四)- 动态代理核心类
- 51 nod 1087 1 10 100 1000 (set)