随笔分类 -  模板

 
容斥原理应用
摘要:typedef __int64 ll;ll gao(ll l,ll r,ll n){//[l,r]内与n互素的数字个数 vector v; for(ll i=2;i*i1)v.push_back(n); int m=v.size(); ll res=0; for(... 阅读全文
posted @ 2014-11-13 23:17 LegendaryAC 阅读(169) 评论(0) 推荐(0)
平面点旋转公式
摘要:任意点(x,y),绕一个坐标点(rx0,ry0)逆时针旋转a角度后的新的坐标设为(x0, y0),有公式:x0= (x - rx0)*cos(a)- (y - ry0)*sin(a) + rx0 ;y0= (x - rx0)*sin(a) + (y - ry0)*cos(a) + ry0 ; 阅读全文
posted @ 2014-10-07 12:23 LegendaryAC 阅读(652) 评论(0) 推荐(0)
矩阵快速幂
摘要:#define MOD 2008#define Mat 35 //矩阵大小 struct mat{//矩阵结构体,a表示内容,r行c列 矩阵从1开始 int a[Mat][Mat]; int r, c; mat() { r = c = 0; ... 阅读全文
posted @ 2014-10-05 01:30 LegendaryAC 阅读(196) 评论(0) 推荐(0)
上下界网络流模型常见解法
摘要:一、无源汇可行流1、设立虚拟源汇S、T,IN[i]记录i点流入下限的总和,OUT[i]记录i点流出下限总和2、两点间连容量为上限-下限的边3、sum=0,遍历所有点i,f=IN[i]-OUT[i]。如果f>0,sum+=f,add(S,i,f);否则,add(i,T,-f)4、如果S到T的最大流等于... 阅读全文
posted @ 2014-10-01 23:44 LegendaryAC 阅读(206) 评论(1) 推荐(0)
欧拉通路和欧拉回路
摘要:转http://www.cnblogs.com/zibuyu/archive/2013/03/14/2960399.html欧拉通路 欧拉回路的区别 及其判定在做一些图类时经常要用到欧拉路,比如近期的单词连接和涂彩棒等,下面整理了一点:欧拉通路: 通过图中每条边且只通过一次,并且经过每一顶点的通路。... 阅读全文
posted @ 2014-08-26 23:39 LegendaryAC 阅读(345) 评论(0) 推荐(0)
高精度模板
摘要:#include #include #include #include #include using namespace std; #define MAXN 9999#define MAXSIZE 10#define DLEN 4class BigInt{ private: int a[50... 阅读全文
posted @ 2014-08-09 21:53 LegendaryAC 阅读(137) 评论(0) 推荐(0)
高斯消元
摘要:#include #include #include #include #include #include #include using namespace std ;const int MAXN=50;int a[MAXN][MAXN];//增广矩阵int x[MAXN];//解集bool fre... 阅读全文
posted @ 2014-07-18 15:00 LegendaryAC 阅读(144) 评论(0) 推荐(0)
并查集
摘要:#define MAX_N 50005int par[MAX_N] ;//父亲 int rank[MAX_N] ;//树的高度 void INIT(int n){ for(int i=0 ;i<n ;i++){ par[i]=i ; rank[i]=0 ; }... 阅读全文
posted @ 2014-07-09 21:50 LegendaryAC 阅读(134) 评论(0) 推荐(0)
计算几何基本函数
摘要:#include #include #include #include #include using namespace std ;const double eps = 1e-8;const double PI = acos(-1.0);int sgn(double x){ if(fabs(x... 阅读全文
posted @ 2014-06-12 18:45 LegendaryAC 阅读(245) 评论(0) 推荐(0)
lca
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2586无根树转有根树,基于rmq算法计算lca,模板题#include #include #include #include #include using namespace std ;const int MAX_... 阅读全文
posted @ 2014-06-11 23:44 LegendaryAC 阅读(186) 评论(0) 推荐(0)
三分
摘要:整数//三分极小值 int Left, Right;int mid, midmid;int mid_value, midmid_value;Left = minn; Right = maxn;while (Right - Left > 5){ mid = (Left + Right) / 2;... 阅读全文
posted @ 2014-06-05 02:29 LegendaryAC 阅读(152) 评论(0) 推荐(0)
平面最近点对
摘要:HDU 1007 求平面最近点对距离的一半#include #include #include #include #include using namespace std;const double eps = 1e-7;const int MAXN = 100010;const double INF... 阅读全文
posted @ 2014-06-04 21:24 LegendaryAC 阅读(186) 评论(0) 推荐(0)
km算法
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2255km模板,二分图最优匹配,复杂度O(n^3)http://www.cnblogs.com/jackge/archive/2013/05/03/3057028.html#include #include #in... 阅读全文
posted @ 2014-05-21 15:24 LegendaryAC 阅读(233) 评论(0) 推荐(0)
AC自动机
摘要:hdu2222 字符串多模匹配算法 采用kuangbin模板#include #include #include #include #include using namespace std;struct Trie{ int next[500010][26],fail[500010],end[5... 阅读全文
posted @ 2014-05-16 14:16 LegendaryAC 阅读(190) 评论(0) 推荐(0)
RMQ
摘要:数组下标0-n-1,询问区间最值int dp[100005][20];void makermq(int n, int *a) { for(int i = 0; i < n; i++) dp[i][0] = a[i]; for(int j = 1; (1<<j) <= n; ... 阅读全文
posted @ 2014-05-14 19:11 LegendaryAC 阅读(109) 评论(0) 推荐(0)
2-sat
摘要:http://blog.sina.com.cn/s/blog_64675f540100k2xj.htmlhttp://www.cppblog.com/MatoNo1/archive/2011/07/13/150766.aspx讲解看的这两篇博客,其实最好直接去看国家集训队的论文,别的抄来抄去想找个原... 阅读全文
posted @ 2014-05-07 17:22 LegendaryAC 阅读(152) 评论(0) 推荐(0)
最大流之dinic
摘要:先用bfs预处理出层次图,然后在层次图上用dfs找增广路径,理论复杂度O(n*n*m)const int INF=0xfffffff ;struct node{ int s,t,cap,nxt ;}e[400005] ;int m,n,cnt,head[100005],level[100005... 阅读全文
posted @ 2014-05-01 13:40 LegendaryAC 阅读(157) 评论(0) 推荐(0)
最小费用最大流
摘要:每边有一个权值,要求得到最大流并且使得权值和最小把EK算法中的bfs改成spfa,spfa需要注意的是进行松弛的边容量不能为0const int INF=0xfffffff ;struct node{ int s,t,cap,cost,nxt ;}e[200005] ;int sumflow ... 阅读全文
posted @ 2014-04-27 19:32 LegendaryAC 阅读(130) 评论(0) 推荐(0)
匈牙利算法
摘要:二分图最大匹配邻接表:O(nm)struct node{ int s,t,nxt ; }e[1005] ;int k,m,n,head[505],cnt,match[505],vis[505] ;int find(int s){ for(int i=head[s] ;i!=-1 ;i=e... 阅读全文
posted @ 2014-04-09 10:52 LegendaryAC 阅读(278) 评论(0) 推荐(0)
spfa
摘要:可判环,可算负权边,编码简单,很强的算法int spfa(int s){ for(int i=1 ;i q ; q.push(s) ; ct[s]++ ; while(!q.empty()) { int u=q.front() ; q.pop... 阅读全文
posted @ 2014-03-12 21:18 LegendaryAC 阅读(169) 评论(0) 推荐(0)