2017西安网络赛B_Coin

样例输入
2
2 1 1
3 1 2
样例输出
500000004
555555560
思路:
n重伯努利实验概率分布题。
设q=1-p,p为事件概率。
Y为出现偶数次的概率。

所以 Y=1/2*((1-2*p)^n+1)
先求快速幂,再求逆元
#include<bits/stdc++.h>
#define LL long long
#define mod 1000000007
using namespace std;
LL quick_pow(LL x, LL n) {
LL res = 1;
x=(x%mod+mod)%mod;
while(n) {
if(n&1)
res=res*x% mod;
n >>=1;
x =x*x% mod;
}
return res;
}
int main()
{
LL p, q;
LL n;
int t;
scanf("%d", &t);
while(t --) {
scanf("%lld%lld%lld",&p, &q, &n);
LL a=quick_pow(p,mod-2);
a=(a*2*q)%mod;
a=(1-a+mod)%mod;
a=quick_pow(a,n)%mod;
a=(a+1)%mod;
LL b=quick_pow(2,mod-2)%mod;
a=(a*b)%mod;
printf("%lld\n", (a%mod+mod)%mod);
}
}
2017西安网络赛B_Coin的更多相关文章
- 2017西安网络赛 F
f(cos(x))=cos(n∗x) holds for all xx. Given two integers nn and mm, you need to calculate the coeffic ...
- 2017西安网络赛C_SUM
样例输入 1 1 样例输出 89999999999999999999999999 题意:利用上述公式,求出k的值 思路:找规律,找规律发现233个9,无论x是何值永远成立 (这种规律题尽量就不用跟队友 ...
- hdu5017:补题系列之西安网络赛1011
补题系列之西安网络赛1011 题目大意:给定一个椭球: 求它到原点的最短距离. 思路: 对于一个椭球的标准方程 x^2/a^2 + y^2/b^2 +z^2/c^2=1 来说,它到原点的最短距离即为m ...
- 2017 ICPC网络赛(西安)--- Xor
题目连接 Problem There is a tree with n nodes. For each node, there is an integer value ai, (1≤ai≤1,000 ...
- 2017西安区域赛A / UVALive - 8512 线段树维护线性基合并
题意:给定\(a[1...n]\),\(Q\)次询问求\(A[L...R]\)的异或组合再或上\(K\)的最大值 本题是2017的西安区域赛A题,了解线性基之后你会发现这根本就是套路题.. 只要用线段 ...
- 2017乌鲁木齐网络赛 j 题
题目连接 : https://nanti.jisuanke.com/t/A1256 Life is a journey, and the road we travel has twists and t ...
- hdu 6152 : Friend-Graph (2017 CCPC网络赛 1003)
题目链接 裸的结论题.百度 Ramsey定理.刚学过之后以为在哪也不会用到23333333333,没想到今天网络赛居然出了.顺利在题面更改前A掉~~~(我觉得要不是我开机慢+编译慢+中间暂时死机,我还 ...
- 2017 ACM-ICPC 西安网络赛 F.Trig Function Chebyshev多项式
自己太菜,数学基础太差,这场比赛做的很糟糕.本来想吐槽出题人怎么都出很数学的题,现在回过头来想还是因为自己太垃圾,竞赛就是要多了解点东西. 找$f(cos(x))=cos(nx)$中$x^m$的系数模 ...
- 2017 icpc 西安网络赛
F. Trig Function 样例输入 2 0 2 1 2 2 样例输出 998244352 0 2 找啊找啊找数列和论文.cosnx可以用切比雪夫多项式弄成(cosx)的多项式,然后去找到了相关 ...
随机推荐
- hdu 4788
#include<stdio.h> #include<math.h> int main() { int a; double d; char s],ch; for;i++) d; ...
- BBS+Blog项目代码
项目目录结构: cnblog/ |-- blog/(APP) |-- migrations(其中文件略) |-- templatetags/ |-- my_tags.py |-- utils/ |-- ...
- [K/3Cloud] 在设计时复制已有表单菜单或菜单项快速建立菜单
1.打开已有表单XML,找到FormAppearance的Menu节点,按Ctrl+C复制 <Appearances> <FormAppearance ElementType=&qu ...
- Bone Collector II(hdu 2639)
题意:求01背包的第k最优值 输入:第一行为T,下面是T组数据,每组数据有n,m,k 代表n件物品,m容量,和题目要求的k,下一行是n个物品的价值,再一行是n个物品的体积 输出:T行答案 /* 类似于 ...
- Our Journey of Dalian Ends 乌鲁木齐网络赛 最小费用最大流
Life is a journey, and the road we travel has twists and turns, which sometimes lead us to unexpecte ...
- Model、ModelMap、ModelAndView的使用和区别
1.Model的使用 数据传递:Model是通过addAttribute方法向页面传递数据的: 数据获取:JSP页面可以通过el表达式或C标签库的方法获取数据: return:return返回的是指定 ...
- HashMap源码分析1:添加元素
本文源码基于JDK1.8.0_45. final V putVal(int hash, K key, V value, boolean onlyIfAbsent, boolean evict) { N ...
- 深入理解windows系统内的GMT和时区
http://www.itshanghai.net/technology/wdzl_windowsxp/ UTC(Universal Time Coordinated)是通用协调时,这两者几乎是一 ...
- 制作svg动画
要实现一步一步画出来一个图片,css3做不到吧.除非一张张的图片定时显示.想不到别的招了.如今用的是一个插件,做了一个svg动画. 插件地址:http://lazylinepainter.info/ ...
- A. Polo the Penguin and Strings
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...