![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
模板锦集
文章平均质量分 70
___Evan
这个作者很懒,什么都没留下…
展开
-
KM模板
int Max( int a,int b ){ return a>=b?a:b;}bool findpath(int u) //给x[u]找匹配,这个过程和匈牙利匹配是一样的{ visx[u] = 1; for( int v=1; v<=ny; v++ ) { if( !visy[v] && lx[u] + ly[v] == map[u][v] )原创 2013-11-28 20:33:48 · 401 阅读 · 0 评论 -
并查集模板
int find( int x ){ if( p[x] == x ) return p[x]; else { return p[x] = find( p[x] ); }}void merge( int a,int b ){ int x = find(a); int y = find(b); if( ra原创 2013-11-29 15:25:45 · 471 阅读 · 0 评论 -
欧几里得算法
欧几里得typedef __int64 LL;LL gcd( LL a,LL b ){ return b == 0?a:gcd(b,a%b);}扩展欧几里得//求整数x和y使得ax+by=d;且|x|+|y|最小。其中d=gcd(a,b);typedef __int64 LL;void gcd( LL a,LL b,LL &d,LL &x,LL &y )原创 2014-02-28 19:45:08 · 418 阅读 · 0 评论 -
数位DP模板
找13int dp[maxn][3],digit[maxn];int dfs( int pos,int st,bool flag ){ if( !pos ) return st == 2; if( flag && dp[pos][st] != -1 ) return dp[pos][st]; int ans = 0; int u = flag?9:digit[pos]; for(原创 2014-04-16 12:00:46 · 567 阅读 · 0 评论 -
KMP
#include#include#include#include#include#include#include#include#includeusing namespace std;const int maxn = 1005;const int inf = 1<<30;//0x7f;typedef __int64 LL;int ans;int Next[maxn];原创 2014-04-02 20:11:41 · 363 阅读 · 0 评论 -
2-Sat
#include #include #include#include #include using namespace std;const int maxn = 100050;const int inf = 1<<30;struct TwoSAT{ int n;; vectorG[maxn<<1]; bool mark[maxn]; int S[maxn<<1],c;原创 2014-04-19 15:07:36 · 338 阅读 · 0 评论 -
博弈模板
首先定义mex(minimal excludant)运算,这是施加于一个集合的运算,表示最小的不属于这个集合的非负整数。例如mex{0,1,2,4}=3、mex{2,3,5}=0、mex{}=0。对于一个给定的有向无环图,定义关于图的每个顶点的Sprague-Grundy函数g如下:g(x)=mex{ g(y) | y是x的后继 },这里的g(x)即sg[x]例如:取石子问题,原创 2014-04-21 10:08:50 · 431 阅读 · 0 评论 -
素数筛选法
bool vis[maxn];int prime[maxn];void sieve( int n ){ int m = (int)sqrt(n+0.5); memset(vis,0,sizeof(vis)); for( int i = 2; i <= m; i ++ ) if( !vis[i] ) for( int j = i*i; j <= n; j += i )原创 2014-02-28 19:36:49 · 537 阅读 · 0 评论 -
Hopcroft-Karp算法模板
http://blog.csdn.net/u011742541/article/details/14104573bool searchpath(){ queueque; dis = inf; memset( dx,-1,sizeof(dx) ); memset( dy,-1,sizeof(dy) ); for( int i = 1; i <= nx; i ++ ) {原创 2013-11-28 20:35:34 · 598 阅读 · 0 评论 -
高精度非负整数
#include #include #include #include #include #include using namespace std;typedef long long LL;const int maxn = 10005;const int Mod = 1000000007;struct bign{ int len,s[maxn]; bign(){ mems原创 2014-07-12 10:16:51 · 452 阅读 · 0 评论 -
RMQ
//预处理void RMQ_init( const vector& A ){ int n = A.size(); for( int i = 0; i < n; i ++ ) d[i][0] = A[i]; for( int j = 1; (1<<j) <= n; j ++ ) for( int i = 0; i + (1<<j) < n; i ++ ) d[i][j] =原创 2014-02-28 20:06:56 · 384 阅读 · 0 评论 -
取模快速幂
__int64 fun( int x ) { __int64 sum = 1,tmp = 26; while( x ){ if( x&1 ){ sum = sum * tmp; sum %= MOD; } tmp = (tmp*tmp)%MOD;原创 2014-01-24 14:47:03 · 521 阅读 · 0 评论 -
SCC Tarjan算法
void tarjan( int u, int fa ){ low[u] = dfn[u] = ++time; S.push(u); for( int i = 0; i < map[u].size(); i ++ ) { int v = map[u][i]; if( !dfn[v] ) { tarj原创 2013-12-05 13:55:14 · 723 阅读 · 0 评论 -
BellmanFord算法模板
http://blog.csdn.net/u011742541/article/details/12916609bool BellmanFord( int s ){ for( int i = 0; i < n; i ++ ) dis[i] = inf; dis[s] = 0; for( int i = 0; i < n-1; i ++ ) //n原创 2013-11-29 14:09:39 · 727 阅读 · 0 评论 -
多重背包模板
void CompletePacc(int cost,int weight) { int i; for(i=cost;i<=v;i++) if(dp[i]<dp[i-cost]+weight) { dp[i]=dp[i-cost]+weight; } }void Zero原创 2013-11-29 15:27:16 · 456 阅读 · 0 评论 -
Floyd算法模板
http://blog.csdn.net/u011742541/article/details/12876415void Floyd(){ int temp=inf; for( int k=1;k<=max_city;k++ ) for( int i=1;i<=max_city;i++ ) if( map[i][k]!=inf ) for( int j=1;j<=m原创 2013-11-29 14:00:59 · 486 阅读 · 0 评论 -
最小生成树模板
#include#include#include#include#includeusing namespace std;const int maxn = 105;const double inf = 100000000.0;int n,m;double dis[maxn];bool vis[maxn];struct Node{ int x,y;}node[maxn];原创 2013-11-29 15:29:28 · 458 阅读 · 0 评论 -
Dinic模板
//多路增广bool Dinic_bfs( int st ){ queueque; for( int i = 0; i <= n; i ++ ) dis[i] = -1; dis[st] = 0; que.push(st); while( !que.empty() ){ int u = que.front(); que.pop(); for( int i = head[原创 2013-11-28 20:31:16 · 515 阅读 · 0 评论 -
Dijstra算法模板
http://blog.csdn.net/u011742541/article/details/12917981int maps[maxn][maxn],dis[maxn];bool vis[maxn];typedef pairpii;void Dijstra( int x ){ priority_queue,greater >que; memset( v原创 2013-11-29 13:57:58 · 644 阅读 · 0 评论 -
SPEA算法模板
http://blog.csdn.net/u011742541/article/details/12916609bool SPEA( int s ){ queueque; memset( outque,0,sizeof(outque) ); memset( vis,0,sizeof(vis) ); for( int i = 0; i < n; i ++ )原创 2013-11-29 15:23:26 · 3040 阅读 · 0 评论 -
ISPA模板
int SAP_Max_Flow( int st,int end ){ int curedge[maxn],pre[maxn],h[maxn],gap[maxn]; int u,neck,tmp,i; memset( h,0,sizeof(h) ); memset( gap,0,sizeof(gap) ); int cur_flow,flow_ans = 0; for( int i原创 2013-11-28 20:28:53 · 604 阅读 · 0 评论 -
割点模板
http://blog.csdn.net/u011742541/article/details/14104613int low[maxn],dfn[maxn];bool iscut[maxn];void tarjan( int u, int fa ){ low[u] = dfn[u] = ++time; int child = 0; for( int i = 0; i < m原创 2013-11-29 15:40:36 · 531 阅读 · 1 评论 -
匈牙利算法
int nx,ny;int map[maxn][maxn]; int cx[maxn],cy[maxn]; bool vis[maxn];int findpath( int u ) { for( int i = 1; i <= ny; i++ ) { if( map[u][i] && !vis[i] ) { vis[i] = 1; i原创 2014-07-31 18:59:30 · 408 阅读 · 0 评论