
我的模板&算法总结
算球?
在校学生
展开
-
组合数计算,防止溢出
#include <iostream>using namespace std;typedef long long ll;ll C(ll n, ll m){ ll res = 1; for(ll i = 1; i <= m; ++i) res = res*(n-m+i)/i; return res;}int main(){ cout << C原创 2017-06-16 13:40:06 · 503 阅读 · 0 评论 -
线性求逆元
#include <iostream>using namespace std;const int N = 10000005;const int mod = 1e9+7;int inv[N];void init(){ inv[1] = 1; for(int i=2; i<N; i++) { if(i >= mod) break; inv[原创 2017-06-12 19:35:34 · 291 阅读 · 0 评论 -
Ford-Fulkerson(最大流)
#include #include #include #include using namespace std;#define MAX_V 1005#define INF 99999999struct edge{ edge(int t = 0,int c = 0, int r = 0):to(t),cap(c),rev(r){} //终点 容量 反向边 in原创 2016-07-01 10:19:24 · 373 阅读 · 0 评论 -
最小费用流模板(Bellman-Ford算法找最短路)
poj 3068#include <stdio.h>#include <string.h>#include <vector>#include <algorithm>using namespace std;struct edge{ int to,cap,cost,rev; edge(int _to = 0, int _cap = 0, int _cost = 0, int _原创 2017-11-03 12:46:20 · 504 阅读 · 0 评论 -
Lucas定理
lucas定理讲解:https://www.math.hmc.edu/funfacts/ffiles/30002.4-5.shtml#include <iostream>#include <string.h>#include <stdio.h>using namespace std;typedef long long LL;LL n,m,p;LL quick_mod(LL a, LL b){原创 2017-07-09 16:55:30 · 293 阅读 · 0 评论 -
归并排序
#include <bits/stdc++.h>using namespace std;const int MAXN = 50100;int num[MAXN];int temp[MAXN];int n;void Merge(int l, int mid, int r){ int rlen = 0; int i = l; int j = mid+1; whi原创 2017-10-17 18:07:33 · 191 阅读 · 0 评论 -
莫比乌斯反演学习资料
PoPoQQQ - 莫比乌斯反演:https://wenku.baidu.com/view/dbedced74b73f242326c5f95.html POI XIV Stage.1 Queries Zap 解题报告:https://wenku.baidu.com/view/fbe263d384254b35eefd34eb.html 莫比乌斯反演入门:http://www.cnblogs.com原创 2017-08-08 09:23:47 · 447 阅读 · 1 评论 -
使用数组模拟邻接表
具体的思路是,在建立邻接表时,记录的不是点而是边,对于每一个点所对应的邻接表都是以栈的形式存储的,也就是说先添加的边在遍历时后取出,除此以外,所有的边用一个结构体数组存储起来,每条边对应的索引就是其编号,在建立邻接表时,表中存放的实质是边的编号,在遍历时先获得编号,在放回结构体数组中获得相应的边的数据。 下面用具体代码解释一下:int top=0;//用来确定当前边的编号 int head[M转载 2017-07-28 20:37:13 · 439 阅读 · 0 评论 -
RMQ (Range Minimum/Maximum Query)算法
1. 概述RMQ(Range Minimum/Maximum Query),即区间最值查询,是指这样一个问题:对于长度为n的数列A,回答若干询问RMQ(A,i,j)(i,j<=n),返回数列A中下标在i,j之间的最小/大值。这两个问题是在实际应用中经常遇到的问题,下面介绍一下解决这两种问题的比较高效的算法。当然,该问题也可以用线段树(也叫区间树)解决,算法复杂度为:O(N)~O(logN),这里我们转载 2017-08-12 20:23:35 · 221 阅读 · 0 评论 -
手动开高次方
也就开到59次根号下。当然精度要比pow(n,1/m)高。 find(x,k)表示x√k\sqrt[k]{x}const LL INF = 1e18+300; const LL T = (1LL<<31);LL pow_mul(LL x,LL k) { LL ans=1; while(k) { if(k&1) {原创 2017-08-18 20:14:17 · 973 阅读 · 0 评论 -
中国剩余定理算法详解(余数互质和不互质)
原文:http://blog.youkuaiyun.com/dafang_xu/article/details/50818919#t0参考: 中国剩余定理: http://itdocument.com/7701006441/ http://www.cppblog.com/qywyh/archive/2007/08/27/30943.aspx 扩展欧几里得算法: http://blog.csd转载 2017-08-08 15:02:57 · 1398 阅读 · 0 评论 -
模运算与同余公式的性质
原文:http://blog.youkuaiyun.com/a359680405/article/details/41675143 所谓的同余,顾名思义,就是许多的数被一个数d去除,有相同的余数。d数学上的称谓为模。如a=6,b=1,d=5,则我们说a和b是模d同余的。因为他们都有相同的余数1。 数学上的记法为: a≡ b(mod d) 可以看出当n <转载 2017-08-08 14:59:13 · 898 阅读 · 0 评论 -
线性筛法求素数
#include <iostream>#include <cstring>using namespace std;const int MAXN = 1e6+10;int prime[MAXN];int numPrime;int isPrime[MAXN];void getPrime(){ numPrime = 0; memset(isPrime,0,sizeof(isPr原创 2017-06-12 17:39:10 · 283 阅读 · 0 评论 -
矩阵快速幂(斐波那契数列)
#include <iostream>#include <vector>using namespace std;typedef long long ll;typedef vector<ll> vec;typedef vector<vec> mat;const ll mod = 1e9+9;mat mul(mat& A, mat &B){ mat C(A.size(),vec(B[原创 2017-06-12 17:06:39 · 311 阅读 · 0 评论 -
分治法编程问题之最接近点对问题的算法分析
问题描述 在应用中,常用诸如点、圆等简单的几何对象代表现实世界中的实体。在涉及这些几何对象的问题中,常需要了解其邻域中其他几何对象的信息。例如,在空中交通控制问题中,若将飞机作为空间中移动的一个点来看待,则具有最大碰撞危险的2架飞机,就是这个空间中最接近的一对点。这类问题是计算几何学中研究的基本问题之一。下面我们着重考虑平面上的最接近点对问题。 最接近点对问题的提法是:给定转载 2016-09-23 20:08:14 · 602 阅读 · 0 评论