ZS and The Birthday Paradox 感觉里面有好多技巧.. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int, int> #define SZ(x…
[题目链接] http://codeforces.com/problemset/problem/711/E [题目大意] 假设一年有2^n天,问k个小朋友中有两个小朋友生日相同的概率. 假设该概率约分后为 p / q ,输出p , q对1000003取模的解. [题解] 当k比天数要大时是肯定成立的,否则答案为1-A(2n,k) / (2n)k, 考虑A(2n,k)=2n*(2n-1)*……*(2n-k+1),所以分子和分母的最大公约数是2的幂次,暴力计算分子分母,以及计算最大公约数的逆元,就可…
传送门 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of \(23\) people,…
已知一年365天找23个人有2个人在同一天生日的概率 > 50% 给出n,k ,表示现在一年有2^n天,找k个人,有2个人在同一天生日的概率,求出来的概率是a/b形式,化到最简形式,由于a,b可能非常大,对a,b分别%(10^6+3) 注意,这道题是先化到最简,再分别取模 首先,特判 k > 2^n 时,a = 1,b = 1 没有2个人同一天生日的概率为: 2^n * (2^n - 1) * ... * (2^n - k + 1) / 2^(nk) 所以a,b化简之前分别是: a = 2nk…
题目大概说给一棵树,树的边一开始都是损坏的,要修复一些边,修复完后要满足各个点到根的路径上最多只有一条坏的边,现在以各个点为根分别求出修复边的方案数,其结果模1000000007. 不难联想到这题和HDU2196是一种类型的树形DP,因为它们都要分别求各个点的答案.然后解法也不难想: dp0[u]表示只考虑以u结点为根的子树的方案数 dp1[u]表示u结点往上走,倒过来,以它父亲为根那部分的方案数 有了这两部分的结果,对于各个点u的答案就是dp0[u]*(dp1[u]+1).这两部分求法如下,画…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is aro…
题目链接: E. ZS and The Birthday Paradox. time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that giv…
E. ZS and The Birthday Paradox 题目连接: http://www.codeforces.com/contest/711/problem/E Description ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% c…
ZS and The Birthday Paradox 题目链接:http://codeforces.com/contest/711/problem/E 数学题(Legendre's formula) 这题是以生日悖论(如果有23个或23个以上的人,那么至少有两个人的生日相同的概率要大于50%)为背景的数学题.公式本身不难推,主要是对大数的处理. 首先,我们需要找到分子和分母的公因数,这里用到了Legendre's formula(举个例子:10!的因数中质数3的个数为[10/3+10/(3^2…
/* cf369E. ZS and The Birthday Paradox http://codeforces.com/contest/711/problem/E 抽屉原理+快速幂+逆元+勒让德定理+费马小定理+欧拉定理+数论 题解:https://amoshyc.github.io/ojsolution-build/cf/cf369/pe.html 坑点: 1.long long 类型的常量一定要加LL,否则1<<n只在int范围内 2.带模的题目,最后一定要判断是否答案为负,答案为负数要…