传送门:  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})​p​​q​​(​p​​q​​≤​2​​1​​).

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}​Y​​X​​, because the answer could be extremely large, you only need to print (X * Y^{-1}) \mod (10^9+7)(X∗Y​−1​​)mod(10​9​​+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≤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

题目来源

2017 ACM-ICPC 亚洲区(西安赛区)网络赛

题目的意思很简单,就是让你扔硬币,给你p,q.向上的概率为q/p;然后问

你向上次数为偶数的概率。

这个地方用到高中组合知识:(组合数学,概率方面的问题)

设 向上概率概率是 a  向下为b  则  a+b =1;

k次 扔 取时 向上为偶数的为:  C(k,0) *a^0 * b^k  + C(k,2) *a^2 *b^(k-

2) +C(k,4)*a^4 *b^(k-4) ......... + C(k,k)*a^k*b^0

(a+b)^k   展开为  : C(k,0)*a^0 *b^k,+ C(k,1)*a^1*b^(k-1)

+C(k,2)*a^2*b^(k-2) .......+C(k,k)*a^k*b^0

(a-b) ^k 展开为:  C(k,0) *a^0 *(-b)^k +C(k,1)^a* (-b)^(k-1)

.........+C(k,k)*a^k*(-b^0)

所以 应为:  ((a+b)^k +(a-b)^k ) /2

题意 要求逆元:

求逆元方法;:(三种)

ll inv_exgcd(ll a,ll n){lld,x,y;ex_gcd(a,n,d,x,y);return d==1?

(x+n)%n:-1;}

ll inv1(ll b){returnb==1?1:(MOD-MOD/b)*inv1(MOD%

b)%MOD;}

ll inv2(ll b){return qpow(b,MOD-2);}

求逆元 应用 费马小定理的那个 即为:

ll inv2(ll b){return qpow(b,MOD-2);}

若用 带/ 法的 求逆元  则会出现 /0 的情况 WA

#include<stdio.h>
#include<iostream>
#include <algorithm>
#include<string.h>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#define LL long long
#define INf 0x3f3f3f3f
const int MOD=1e9+7;
using namespace std;
LL qpow(LL x,LL n)
{LL res=1;for(;n;n>>=1){if(n&1)res=(res*x)%MOD;x=(x*x)%MOD;}return res;
}
LL inv2(LL b)
{return qpow(b,MOD-2);
}
int main()
{int t;  scanf("%d",&t);while(t--)  {  LL p,q,k;  scanf("%lld %lld %lld",&p,&q,&k);  LL a=qpow(p,k);  LL sum=(a+qpow((p-2*q),k))%MOD;;  sum=sum*(inv2(2*a)%MOD);  printf("%lld\n",sum%MOD);  }  return 0;
} 

2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B Coin (概率计算)相关推荐

  1. 计蒜客 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B coin(求乘法逆元)

    Bob has a not even coin, every time he tosses the coin, the probability that the coin's front face u ...

  2. Maximum Flow(2017 ACM-ICPC 亚洲区(西安赛区)网络赛 E)

    Problem Description Given a directed graph with nn nodes, labeled 0,1,⋯,n−1. For each <i, j> s ...

  3. 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 E Maximum Flow

    原题解链接:http://blog.csdn.net/kkkkahlua/article/details/78009087 他用的最小割的来求解最大流.认为只要讨论每一个点到0和n-1那个更小哪条边就 ...

  4. 2016 ACM/ICPC亚洲区青岛站现场赛(部分题解)

    摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5 ...

  5. 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛B: Out-out-control cars

    问题 B: Out-out-control cars 题目描述 Two out-of-control cars crashed within about a half-hour Wednesday a ...

  6. Skiing(2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 H)

    Problem Description In this winter holiday, Bob has a plan for skiing at the mountain resort. This s ...

  7. 计蒜客-2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛H题Skiing(拓扑序求DAG最长路)

    题意: 给定一个有向无环图,求该图的最长路. 思路: 由于是有向无环图,所以最长路肯定是一个入度为0到出度为0的路径,拓扑序在确定当前点之前能够考虑到所有到它的情况,所以最后取个最值即可. 代码: # ...

  8. 2017 ACM/ICPC(西安)赛后总结

    早上8:00的高铁,所以不得不6点前起床,向火车站赶--到达西安后已经是中午,西工大距离西安北站大概3小时车程的距离,只好先解决午饭再赶路了--下午3.30的热身赛,一行人在3.35左右赶到了赛场,坐 ...

  9. 2010 ACM/ICPC Online-Contest-SCU[四川赛区网络预选赛]

    Problem A.A Simple Problem 比赛时唯一做出来的一道题. 描述: Time limit: 1 second Memory limit: 256 megabytes There' ...

  10. 2014 ACM/ICPC 北京赛区网络赛解题报告汇总

    首页 算法竞赛» 信息聚合 ONLINE JUDGE 书刊杂志 BLOG» 新闻故事» 招聘信息» 投稿须知 2014 ACM/ICPC 北京赛区网络赛解题报告汇总 九月 21st, 2014 | P ...

最新文章

  1. matlab fittype 求不出参数,[转]matlab 中fit fittype
  2. iOS:通过URL构件UIImage
  3. doxygen问题集锦
  4. Response.Redirect 编码的问题
  5. linux新手常用命令
  6. 【Twitter】时序图神经网络
  7. 测试开发之测试方法第一篇
  8. NJUPT_CTF easychallenge 解题脚本
  9. 最全的HTTP1.1状态码
  10. Palo Alto推出全新Traps高级终端功能,强化勒索软件防御优势
  11. 数学建模酶促反应matlab求解,数学建模实验指导书2011
  12. python插件安装包_Python的插件安装
  13. 凝视联通4G和4G+战略落地半年报,从数据亮点中找出路
  14. c/c++原子锁应用(跨平台)
  15. Python度分秒与度的互转
  16. EAN13码校验位算法
  17. 项目完整上线流程-后端
  18. 前端人员如何在页面中导入外部字体
  19. DataV中数字翻牌器的使用
  20. unity快速开发问答游戏

热门文章

  1. 什么是CISP-PTE证书?考什么?
  2. Shell攻关之正则表达式
  3. DRF-视图类APIView与GenericAPIView
  4. go: cannot find main module, but found .git/config in
  5. 全国信息竞赛语言有python吗_2019年全国信息学竞赛有哪些
  6. (转)如何获得两个日期相减的天数?
  7. 海信a5,掌阅f1手机水墨屏护眼日常使用经验
  8. 安装jre运行环境_如何下载安装java运行环境jre
  9. python3使用opencv读取raw格式图片并保存为bmp格式图片
  10. fastreport 横向打印多列