2017 icpc 西安赛区 B.Coin(推公式+二项式定理)
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
题目来源
2017 ACM-ICPC 亚洲区(西安赛区)网络赛
【题解】
一道数学题,要结果的逆元,不过要先推公式,推出来再用二项式定理化简,就能写了。
【AC代码】
#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<cmath>
#include<vector>using namespace std;typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;#define pi acos(-1.0)
#define eps 1e-10
#define pf printf
#define sf scanf
#define lson rt<<1,l,m
#define rson rt<<1|1,m+1,r
#define e tree[rt]
#define _s second
#define _f first
#define all(x) (x).begin,(x).end
#define mem(i,a) memset(i,a,sizeof i)
#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)
#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)
#define mi ((l+r)>>1)
#define sqr(x) ((x)*(x))const int inf=0x3f3f3f3f;
const int mod=1e9+7;
int t;
ll p,q,k;ll quick(ll x,ll y)
{ll ans=1;while(y){if(y&1)ans=ans*x%mod;y>>=1;x=x*x%mod;}return ans;
}ll fact(ll x,ll y)
{ll ans=1;for(int i=x,j=1;j<=y;j++,i--)ans*=i;for(int i=1;i<=y;i++)ans/=i;return ans;
}void solve()
{ll ans=0;ll o=0,y;for(int i=0;i<=k;i+=2){o+=fact(k,i)*quick(p-q,k-i)*quick(q,i);}y=quick(p,k);pf("%lld %lld\n",o,y);
}int main()
{sf("%d",&t);while(t--){sf("%lld%lld%lld",&p,&q,&k);
// ll x=p>>1;
// ll y=p/2-q;ll t1=quick(p,k);ll t2=quick(p-2*q,k);ll u=quick(2,mod-2);//注意不能直接除ll t3=((t1+t2)%mod)*u%mod;ll r=quick(p,k);ll ans=t3*quick(r,mod-2)%mod;pf("%lld\n",ans);}return 0;
}
2017 icpc 西安赛区 B.Coin(推公式+二项式定理)相关推荐
- 计蒜客 17115 2017 ICPC 西安网络赛 B Coin
Problem nanti.jisuanke.com/t/17115 Reference 关于二项展开式系数和 [二项式定理][推导]计蒜客17115 2017 ACM-ICPC 亚洲区(西安赛区)网 ...
- 2017 ICPC西安区域赛 A - XOR (线段树并线性基)
链接:https://nanti.jisuanke.com/t/A1607 题面: Consider an array AA with n elements . Each of its element ...
- 2017 ICPC西安区域赛 A - XOR ,线段树合并线性基
题目链接:A - XOR 题意;给个数组,每次询问一个区间你可以挑任意个数的数字异或和 然后在或上k的最大值 题解:线性基不知道的先看这个,一个线性基可以log的求最大值把对应去区间的线性基求出来然后 ...
- 2014 ACM/ICPC 北京赛区网络赛解题报告汇总
首页 算法竞赛» 信息聚合 ONLINE JUDGE 书刊杂志 BLOG» 新闻故事» 招聘信息» 投稿须知 2014 ACM/ICPC 北京赛区网络赛解题报告汇总 九月 21st, 2014 | P ...
- 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 ...
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B Coin (概率计算)
传送门: https://nanti.jisuanke.com/t/17115 Bob has a not even coin, every time he tosses the coin, the ...
- 计蒜客 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 ...
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛
这个西安赛区大概是我们学校打得最好的一次了,因为数学题多,而且嘛,那个I竟然就是暴力,恭喜我们学校分了个机会 Coin 问答 只看题面 23.46% 1000ms 32768K Bob has a n ...
- 2017 ACM/ICPC 南宁赛区小结 By JSB @ Reconquista
Statistics TYPE: Onsite Contest NAME: 2017 - ICPC - Asia Nanning PLAT: pc^2 TIME: 2017/11/26 09:00-1 ...
最新文章
- 腾讯竟然是这样招人的,哈哈哈哈哈
- android短信安全,[原创]分析了一款android短信木马
- STM32F4 HAL库开发 -- STM32F407引脚图
- CVE-2015-0235: GHOST – A Critical Vulnerability in the Glibc Library
- 计算机管理系统绪论,数据库系统概论 第一章 绪论
- mysql触发器delimiter_MySQL的触发器创建之注意事项(有关delimiter)
- 中美线径对照表_电缆里线规AWG的标准是什么?和其他公制如何对照使用?
- jdk环境变量的配置
- 无线覆盖技术的重要性
- 速达软件无法打开帐套数据库/一般性网络错误
- 建筑识图与构造【2】
- 关于Optical Zoom
- 为什么说串行比并行快
- 二分法求三次方根代码
- 无线点菜宝服务器,餐饮业电子产品无线点菜宝
- 虚拟屏幕与云计算————微软亚洲研究院
- Qt (高仿Visio)流程图组件开发(三) 图元基类如何定义,流程图多种图元类型实现
- 寻找子树和子孙树 ,家谱树
- 认识Linux操作系统
- 标普500指数下跌2.4%至盘中低点