
数学
huanzhizun
这个作者很懒,什么都没留下…
展开
-
扩展欧几里得
int x,y;int exgcd(int a,int b){ if(b==0) { x=1; y=0; return a; } int p,t; p=exgcd(b,a%b); t=x; x=y; y=t-a/b*y; return p;}原创 2014-04-29 09:28:01 · 515 阅读 · 0 评论 -
Pollard_rho算法(大整数的因子分解或判断是否为素数)
#include#include#include#include#include#includeusing namespace std;//****************************************************************// Miller_Rabin 算法进行原创 2014-09-05 08:19:05 · 811 阅读 · 0 评论 -
分解大数质因数模板
#include#include#include#include#include#includeusing namespace std;//****************************************************************// Miller_Rabin 算法进行素数测试//速度快,而且可以判断 <2^63的数//********原创 2014-09-05 08:17:43 · 1269 阅读 · 0 评论 -
布丰投针问题
/*间距为D的平行直线,一根长为l的针(l针与直线相交的概率是2*l/(pai*d).如果是一个凸包,则概率是C/(pai*d),即为sigma(2*l/(pai*d))/2.因为直线与凸包相交必然与两条边相交,所以概率除以2.*/原创 2014-09-05 11:08:36 · 2139 阅读 · 0 评论 -
hdu 4983 Goffi and GCD(欧拉函数)
k!=1时情况很简单,下面仅tao'l原创 2014-08-25 09:41:24 · 552 阅读 · 0 评论 -
调和级数求和
1/1+1/2+1/3...+1/n~ln(n+1) +r,r是欧拉常数,r=原创 2014-09-05 08:24:35 · 7851 阅读 · 0 评论 -
poj3557 Map Generator(概率dp)及其扩展
对于原题:假如说i原创 2014-10-23 16:18:01 · 652 阅读 · 0 评论 -
布丰投针问题
/*间距为D的平行直线,一根长为l的针(l针与直线相交的概率是2*l/(pai*d).如果是一个凸包,则概率是C/(pai*d),即为sigma(2*l/(pai*d))/2.因为直线与凸包相交必然与两条边相交,所以概率除以2.*/原创 2014-10-14 09:53:12 · 893 阅读 · 0 评论 -
hdu 5209 Magic Toy Brick
我们先考虑对于一行p个人有多少种图案,首先撇去顺序,我们社xi表示h为i的个数,所以x1+....+xm=p,xi>=0因为大小是确定的所以不用管大小顺序,所以方案数是C(p+m-1,m-1),所以剩下的就是dp,我们令dp[i]表示砖头数为i的方法数,我们只需考虑第一行假如是j那么dp[i]+=dp[i-j]*C(i-1,j-1)*C(j+m-1,m-1)(因为第一块肯定是第一行,剩下j-1原创 2015-04-20 22:30:41 · 667 阅读 · 0 评论 -
hdu 5255 魔法因子 百度之星1004
枚举长度,然后枚举首尾元素,可以列出一个方程来解。#include#include#include#includeusing namespace std;typedef long long lll;int gcd(int p,int q){ if(q==0) return p; return gcd(q,p%q);}lll fa[10];lll b[10000原创 2015-05-31 21:42:43 · 725 阅读 · 0 评论 -
hdu4728 PowMod(2016多校第一场1006)
欧拉函数是积性函数,所以从质数入手,对于n的每一个质数我们考虑如果1~m中不是p的倍数那么直接乘(p-1),否则乘以(p-1)之后因为里面也多乘了,所以应该加上sigma(eula(i*n))*(1/p),其中i=1~m/p最后公式等于sum(n,m)=φ(p)∗sum(pn,m)+sum(n,pm)。k求出来后用欧拉定理递归求值。#include#include#原创 2016-07-20 17:28:01 · 478 阅读 · 0 评论 -
Acdream 1148 GCD SUM 莫比乌斯
公式很好推,s1=sigma(u[i]*(m/i)*(n/i),s2=sigma(u[i]*n/i*(m/i+1)*m/i*i/2),s3=sigma(u[i]*原创 2014-08-04 23:50:58 · 574 阅读 · 0 评论 -
Acdream 1065 同心树(数学)
用数学方法计算。原创 2014-07-11 11:33:09 · 543 阅读 · 0 评论 -
约瑟夫环问题
考虑递推。第一次第m个人没了,然后对每个人重新编号原创 2014-06-29 15:49:26 · 537 阅读 · 0 评论 -
2013长沙赛区第一题 HDU4565—So Easy!
此题注意一点就是b>(a-1)^2,b原创 2014-04-30 19:38:34 · 568 阅读 · 0 评论 -
poj 1850组合数学
很简单的组合问题。原创 2014-05-05 14:46:56 · 754 阅读 · 1 评论 -
欧拉错排公式
void init(){ s[0]=0; s[1]=0; s[2]=1; int i; for (i=3;i<=100;i++) s[i]=(i-1)*(s[i-1]+s[i-2])%mod;}原创 2014-04-28 12:38:51 · 2704 阅读 · 0 评论 -
(求极值)三分模板
//三分求极值法// 二分法早就失去了他的意义了。不过还是可以用三分法来实现的,就是二分中再来二分。比如我们定义了L和R,m = (L + R) / 2,mm = (mid + R) / 2; 如果mid靠近极值点,则R = mm;否则就是mm靠近极值点,则L = m;这样的话,极值还是可以求的#include#include#includeusing namespace std;原创 2014-04-28 12:40:36 · 827 阅读 · 0 评论 -
卢斯卡定理模板(大数组和)
#include#include#include#include#includeusing namespace std;__int64 p;__int64 jieji[200005];__int64 ppow(__int64 n,__int64 m){ __int64 s=1,k=n%p; while(m>0) { if(m&1)原创 2014-04-28 12:57:35 · 1032 阅读 · 0 评论 -
莫比乌斯反演
#include#include#include#include#define max 100000using namespace std;int u[max+20];long long f[max+20];long long g[max+20];bool vis[max+20];int mmax(int a,int b){ int p; p=a; i原创 2014-04-29 08:42:33 · 587 阅读 · 0 评论 -
母函数
#include using namespace std;const int _max = 10001;// c1是保存各项质量砝码可以组合的数目// c2是中间量,保存每一次的情况int c1[_max], c2[_max];int main(){ //int n,i,j,k; int nNum; // int i, j, k;原创 2014-04-29 09:28:44 · 512 阅读 · 0 评论 -
Codeforces Round #251 (Div. 2) D Devu and his Brother
因为答案可以看成函数,所以可以用三分来解答。原创 2014-06-05 15:08:45 · 551 阅读 · 0 评论 -
HDU 4336 Card Collector
用状态压缩来表示当前已经取的卡片,原创 2014-06-07 20:08:13 · 535 阅读 · 0 评论 -
平面的划分
己知经过同一个的n个平面,任意三个平面不经过同一条直线,若这n个平面将空间分成f(n)个部分,则f(3)= f(n)= (1)、f(3)=8 (2)、当n>3时,每增加一个面,这面就要与前面n-1个面都相交,因为过同一点,两平面如果有一个公共点就有一条公共直线,这样就会把前面平面划分的空间一分为二,f(n)-f(n-1)=2(n-1),然后累加得f(n)=n^2-n+2原创 2014-06-29 15:43:46 · 795 阅读 · 0 评论 -
hdu 5852 Intersection is not allowed! (2016多校第九场1009)组合
这是一道公式题,虽然想了半天也想不出来,https://en.wikipedia.org/wiki/Lindström–Gessel–Viennot_lemma看这个就行了。#include#include#include#includeusing namespace std;typedef long long LL;const int maxn=200005;const int原创 2016-08-16 22:33:10 · 956 阅读 · 0 评论