- 博客(24)
- 资源 (2)
- 收藏
- 关注
原创 bzoj 1036 树链剖分 迭代 模板
#include#include#include#include#includeusing namespace std;const int N=30010;int n,m,tot,head[N],next[N*2],to[N*2],val[N],pre[N],dep[N],q[N],size[N],son[N],top[N],w[N],id[N];int MAX[N<<2],sum
2015-08-19 12:53:03
364
原创 dinic 模板
void addedge(int u,int v,int c){ e[cnt].v=v; e[cnt].c=c; e[cnt].next=head[u]; head[u]=cnt++; e[cnt].v=u; e[cnt].c=0; e[cnt].next=head[v]; head[v]=cnt++;}int dfn[3000
2015-08-18 20:11:43
297
原创 斯特林数 组合数
///斯特林数 dp[0][0] = dp[1][1] = 1; for(int i = 2;i<N;i++){ dp[i][1] = dp[i-1][i-1]; for(int j = 2;j<=i;j++){ dp[i][j] = (dp[i][j-1] + dp[i-1][j-1]) % MOD;
2015-08-18 20:11:02
569
原创 线段树的两种查询方式
int query(int l,int r,int id,int ll,int rr){ if(ll<=l&&r<=rr) { return tree[id].maxn; } int ans=-1; int mid=(l+r)>>1; if(mid>=ll) { ans=max(ans,query(l,mid
2015-08-18 20:10:29
449
原创 强连通分量 模板
忘了哪道题了,直接发全部代码,需要时改着用。#include#include#include#include#includeusing namespace std;int m,n,k,cas;int x,y;vector ans;int t;vector e[11000];///vector be[11000];int sco[6000];int belong[110
2015-08-18 20:09:41
383
原创 后缀数组 模板
const int maxn=500000;char str[maxn];int wa[maxn],wb[maxn],wv[maxn],wn[maxn],a[maxn],sa[maxn];int cmp(int* r,int a,int b,int l){ return r[a]==r[b]&&r[a+l]==r[b+l];}///n为字符串长度,m为字符的取值范围,r为字符串
2015-08-18 20:07:35
318
原创 割点 割边 模板
int dfn[M],low[M],head[M],vis[M];bool cut[M];int e,n,cnt,root;struct E{ int to,nxt;}edge[M*M];void addedge (int cu,int cv){ edge[e].to = cv; edge[e].nxt = head[cu]; head[cu] =
2015-08-18 20:06:46
514
原创 费用流 模板
void addedge(int u,int v,int c,int w){ e[cnt].v=v; e[cnt].c=c; e[cnt].w=w; e[cnt].next=head[u]; head[u]=cnt++; e[cnt].v=u; e[cnt].c=0; e[cnt].w=-w; e[cnt].next=hea
2015-08-18 20:06:05
354
原创 二分图最大权匹配 模板
/******************************************************二分图最佳匹配 (kuhn munkras 算法 O(m*m*n)).邻接矩阵形式 。 返回最佳匹配值,传入二分图大小m,n邻接矩阵 mat ,表示权,match1,match2返回一个最佳匹配,为匹配顶点的match值为-1,一定注意m<=n,否则循环无法终止,最小权匹配可将全
2015-08-18 20:05:23
330
原创 sap 模板
#define MAXN 1111 //邻接表要开边数的2倍struct Edge{ int v,cap,next;}edge[MAXN];int level[MAXN];//标记层次(距离标号)//间隙优化,定义gap[i]为标号是i的点的个数//在重标记i时,检查gap[level[i]],若减为0,这算法结束。int gap[MAXN];int pre[MAXN]
2015-08-18 20:04:12
403
原创 UVALive 6129 Sofa, So Good
注意题意为先满足第一种操作总花费时间最小,在进行第二次操作并满足总时间最小。 两次二分图最大全匹配,第一次从工人到沙发连边,权值为第一次操作花费时间,第二次从沙发到工人连边,权值为工人开始工作的时间加上第二次操作的时间。 本人采用费用流写法,最后从残余网络找到答案。#include#include#include#include#includeusing namespace std;
2015-08-18 19:59:58
578
原创 UVALive 6124 Hexagon Perplexagon
直接进行搜索即可,注意细节。 有更简便的写法但怕出错所以写得很长。#include#include#include#include#includeusing namespace std;struct node{ int a[6];}he[7];bool flag;int ans[10];int tun[10];bool vis[10];void dfs
2015-08-18 19:55:16
532
原创 [TOJ 1965] Gnome Tetravex
Hart is engaged in playing an interesting game, Gnome Tetravex, these days. In the game, at the beginning, the player is given n*n squares. Each square is divided into four triangles marked four numbe
2015-08-18 19:52:52
301
原创 [TOJ 1029] Robbery
Inspector Robstop is very angry. Last night, a bank has been robbed and the robber has not been caught. And this happened already for the third time this year, even though he did everything in his pow
2015-08-18 19:50:16
356
原创 [TOJ 2663] Concert Hall Scheduling
You are appointed director of a famous concert hall, to save it from bankruptcy. The hall is very popular, and receives many requests to use its two fine rooms, but unfortunately the previous director
2015-08-18 19:46:52
407
原创 [TOJ 3541] Counting Sequences
For a set of sequences of integers {a1, a2,a3, ..., an}, we define a sequence {ai1,ai2, ai3, ..., aik} in which 1 ≤i1 i2 i3 ik ≤ n, as the sub-sequence of {a1, a2, a3, ..., an}. It is quite
2015-08-18 19:42:06
408
原创 [TOJ 3655] Bomb
The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If the current number sequence inc
2015-08-18 19:38:03
328
原创 [TOJ 3978] Probability II
3978. Probability IIBefore read this problem, you should read the problem "Probability I" to get some background information.In fact, Bob is far more intelligent than we have imagined. He
2015-07-20 13:10:06
355
原创 [TOJ 4108] Hearthstone
比赛时拿到了一血,但这个确实是一道很水的题。 通缉怪兽卡和魔法卡可以达到的伤害用来以最少的消耗破坏对方的怪兽,再特判一下是否可以直接用魔法卡获胜。#include#includeusing namespace std;int dp[1000000];int cost[1000000];int aa[1000000];int main(){ int n,m,a,b;
2015-07-15 11:02:29
317
原创 [TOJ 4124] Function
当时现场比赛时被这道题坑惨了,几乎全部的时间都浪费在这道题上面,而且最后还没做出来。 最后顺着某屌的想法才做出来。 同余的时候一定要选择质数。#include#include#include#includeusing namespace std;const long long mod=1000000007;//必须是个质数long long n;int main(){
2015-07-15 10:54:31
321
原创 [TOJ 1636] Going Home
只需要在每个m和H之间进行连边,边权为曼哈顿距离。 然和可以采用二分图最大权匹配或者是费用流。#include#include#include#include#include#includeusing namespace std;const int MAX=310;const int INF=1010101010;struct mcmf{ struct Edge
2015-07-15 10:03:45
402
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人