随笔分类 -  数学--------------------------

上一页 1 ··· 4 5 6 7 8
摘要:【算法】数学 【题解】n!的位数相当于ans=log10(n!)上取整,然后就可以拆出来加了。 可以用log10(i)或log(i)/log(10) 阶乘好像有个斯特林公式…… #include<cstdio> #include<cmath> using namespace std; int mai 阅读全文
posted @ 2017-05-29 22:20 ONION_CYC 阅读(276) 评论(0) 推荐(0)
摘要:【算法】快速幂运算 【题解】快速幂的原理是把幂用二进制表示,从最低位a,次低位a2,次次低位(a2)2。 #include<cstdio> long long quick_pow(long long a,long long b,long long c) { long long ans=1; whil 阅读全文
posted @ 2017-05-28 18:37 ONION_CYC 阅读(239) 评论(0) 推荐(0)
摘要:【算法】欧几里德算法 #include<cstdio> int gcd(int a,int b) {return b==0?a:gcd(b,a%b);} int main() { int a,b; scanf("%d%d",&a,&b); printf("%lld",1ll*a*b/gcd(a,b) 阅读全文
posted @ 2017-05-26 19:05 ONION_CYC 阅读(186) 评论(0) 推荐(0)
摘要:【算法】欧几里德算法 #include<cstdio> int gcd(int a,int b) {return b==0?a:gcd(b,a%b);} int main() { int a,b; scanf("%d%d",&a,&b); printf("%d",gcd(a,b)); return 阅读全文
posted @ 2017-05-26 19:04 ONION_CYC 阅读(118) 评论(0) 推荐(0)
摘要:【算法】简单数学 【题解】多项式展开:(a*b)%p=(a%p*b%p)%p #include<cstdio> #include<algorithm> #define rep(i,j,k) for(int i=j;i<=k;i++) using namespace std; int n,p; int 阅读全文
posted @ 2017-05-24 19:24 ONION_CYC 阅读(294) 评论(0) 推荐(0)
摘要:【算法】高斯消元 【题解】 高斯消元经典题型:异或方程组 poj 1222 高斯消元详解 异或相当于相加后mod2 异或方程组就是把加减消元全部改为异或。 异或性质:00 11为假,01 10为真。与1异或取反,与0异或不变。 建图:对于图上每个点x列一条异或方程,未知数为n个灯按不按,系数为灯i按 阅读全文
posted @ 2017-03-24 19:58 ONION_CYC 阅读(294) 评论(0) 推荐(2)
摘要:【算法】高斯消元 【题解】 建矩阵; for i 找到同列绝对值最大数字; 交换; for k(行) j(列)(倒序) 除法; for i(倒序) for j 减去已知元素 除到右边; #include<cstdio> #include<algorithm> #include<cmath> #inc 阅读全文
posted @ 2017-03-24 13:33 ONION_CYC 阅读(182) 评论(0) 推荐(0)
摘要:【算法】矩阵快速幂 【题解】T*A(n-1)=A(n)矩阵如下: a 1 * x(n-1) 0 = xn 0 0 1 c 0 c 0 防止溢出可以用类似快速幂的快速乘。 #include<cstdio> #include<algorithm> #define ll long long using n 阅读全文
posted @ 2017-03-09 22:05 ONION_CYC 阅读(350) 评论(0) 推荐(0)
摘要:【算法】矩阵快速幂 【题解】 根据f[n]=f[n-1]+f[n-2],可以构造递推矩阵: $$\begin{vmatrix}1 & 1\\ 1 & 0\end{vmatrix} \times \begin{vmatrix}f_n \\ f_{n-1} \end{vmatrix}=\begin{vm 阅读全文
posted @ 2017-03-09 15:31 ONION_CYC 阅读(192) 评论(0) 推荐(0)
摘要:【算法】数学 【题解】 其实就是求中位数,奇数个点就是最中间的点,偶数个点就是最中间两个点和它们之间的区域皆可(所以偶数不必取到两点正中央,取两点任意一点即可)。 我们可以想象现在x轴上有n个点,我们设定的目标点在最左边,那么可以算出距离总和ans。 目标点往右移动1,相当于ans+左边点数-右边点 阅读全文
posted @ 2017-01-18 11:04 ONION_CYC 阅读(380) 评论(0) 推荐(0)
摘要:【算法】扩展欧几里德算法(模线性方程) 【题解】http://hzwer.com/2121.html 一些问题写在http://www.cnblogs.com/onioncyc/p/6146143.html PS:下述代码有问题,具体看上面网站。 #include<cstdio> #include< 阅读全文
posted @ 2016-12-09 14:10 ONION_CYC 阅读(220) 评论(0) 推荐(0)
摘要:【算法】欧几里德算法 【题解】紫书原题 #include<cstdio> #include<algorithm> using namespace std; const int maxn=10010; int T,t,n,a[maxn]; int gcd(int a,int b) {return b= 阅读全文
posted @ 2016-12-08 20:07 ONION_CYC 阅读(231) 评论(0) 推荐(0)
摘要:【数论】数论——onion_cyc 【计数问题】计数问题(排列组合,容斥原理,卡特兰数)——onion_cyc 【概率与期望】链接 【链与反链】链接 【生成树计数(矩阵树定理)】专题链接 【快速幂】 原理:将指数化为二进制再分为若干个数相乘。 每次自己乘自己相当于平方,增加二进制权。 int qui 阅读全文
posted @ 2016-12-08 19:25 ONION_CYC 阅读(1096) 评论(0) 推荐(0)
摘要:【算法】扩展欧几里德算法 【题解】学完扩欧就可以随便水了。。。 转化为不定方程ax-by=1。 因为1且题目保证有解,所以方程有唯一解。 紫书曰:同余方程的一个解其实指的是一个同余等价类。 所以满足x≡x'(mod b)的其他x'也是方程的解。 题目求最小正整数解,因此ans=x%b。 #inclu 阅读全文
posted @ 2016-12-08 19:24 ONION_CYC 阅读(333) 评论(0) 推荐(0)
摘要:【算法】快速幂运算 【题解】ans=(m*10^k+x)%n,用快速幂计算10^k即可,复杂度为O(log k)。 #include<cstdio> long long n,m,k,x,ans; long long quickpow(long long x,long long n,long long 阅读全文
posted @ 2016-08-13 21:40 ONION_CYC 阅读(263) 评论(0) 推荐(1)
摘要:【算法】找规律(听说还有写RMQ的www) 【题解】ans+=(a[i]-a[i-1]) (i=1...n)(a[i]>a[i-1]) 后面比前面大k,说明要新叠加k个区间来达到所需高度。(看似很复杂的区间覆盖问题,从前往后扫描就很容易得到贪心策略) #include<cstdio> int n,a 阅读全文
posted @ 2016-08-13 07:53 ONION_CYC 阅读(237) 评论(0) 推荐(0)
摘要:【算法】贪心 【题解】如果看重一对,先选择其中一个点,该点相邻最大的肯定被选走。所以答案就是最大的[所有点的次大连边点]啦。 #include<cstdio> #include<algorithm> #include<cmath> #include<cctype> #include<cstring> 阅读全文
posted @ 2016-08-12 21:27 ONION_CYC 阅读(293) 评论(0) 推荐(0)
摘要:【算法】数论 【题解】均分的本质是A整除B,A整除B等价于A的质因数是B的子集。 1.将m1分解质因数,即m1=p1^a1*p2^a2*...*pk^ak 所以M=m1^m2=p1^(a1*m2)*p2^(a2*m2)*...*pk^(ak*m2) 2.如果s[i](细胞初始个数)不能被M分解出来的 阅读全文
posted @ 2016-08-12 21:15 ONION_CYC 阅读(806) 评论(0) 推荐(0)
摘要:【算法】 【算法】网络流 【算法】树 【算法】数学 ————【专题】生成树计数(矩阵树定理) ————【专题】计数问题(排列组合,容斥原理,卡特兰数) ————【算法专题】卡特兰数(计数数列) ————【专题】数论 ————【专题】概率和期望 【算法】动态规划 【算法】数据结构 ————【专题】平衡 阅读全文
posted @ 2016-08-10 21:08 ONION_CYC 阅读(2144) 评论(0) 推荐(6)
摘要:Day1 T1(暴力):大水题 #include<cstdio> const int ok[5][5]={ 0,0,1,1,0, 1,0,0,1,0, 0,1,0,0,1, 0,0,1,0,1, 1,1,0,0,0, }; int a[210],b[210]; int main() { int n, 阅读全文
posted @ 2016-08-10 08:20 ONION_CYC 阅读(431) 评论(0) 推荐(2)

上一页 1 ··· 4 5 6 7 8