每一项按顺序理解之后裸敲,每个代码最多15分钟,用模板题来测,超过15分钟算未理解

线段树

平衡树( Treap , sbt , spt )

#include <iostream>
#include <cstdio>
using namespace std ;
const int N = ;
struct node {
int lr , rr , r , v ;
node(){}
node( int lr , int rr , int r , int v ):lr(lr),rr(rr),r(r),v(v) {}
};
struct Treap {
node e[N];
int root , size ;
void init() {
size = ; root = - ;
}
void Rot_l( int &o ) {
int tmp = e[o].rr ;
e[o].rr = e[tmp].lr ;
e[tmp].lr = o ;
o = tmp ;
}
void Rot_r( int &o ) {
int tmp = e[o].lr ;
e[o].lr = e[tmp].rr ;
e[tmp].rr = o ;
o = tmp ;
}
void insert( int &o , int v , int r ) {
if( o == - ) {
o = size++ ;
e[o].lr = e[o].rr = - ;
e[o].r = r , e[o].v = v ;
} else if( v < e[o].v ) {
insert( e[o].lr , v , r ) ;
if( e[ e[o].lr ].r > e[o].r ) Rot_r(o) ;
} else {
insert( e[o].rr , v , r );
if( e[ e[o].rr ].r > e[o].r ) Rot_l(o) ;
}
}
void remove( int &o , int x ) {
if( e[o].v == x ) {
if( e[o].lr == - ) {
o = e[o].rr ;
} else if( e[o].rr == - ) {
o = e[o].lr ;
} else {
if( e[ e[o].lr ].r > e[ e[o].rr ].r ) {
Rot_r(o);
remove( e[o].rr , x );
} else {
Rot_l(o);
remove( e[o].lr , x ) ;
}
}
} else if( e[o].v > x ) {
remove( e[o].lr , x ) ;
} else {
remove( e[o].rr , x ) ;
}
}
int Find_max( int o ) {
if( o == - ) return - ;
while( e[o].rr != - ) o = e[o].rr ;
cout << e[o].r << endl ;
return e[o].v ;
}
int Find_min( int o ) {
if( o == - ) return - ;
while( e[o].lr != - ) o = e[o].lr ;
cout << e[o].r << endl ;
return e[o].v ;
}
} T ; int Run () {
int op , x , y ;
T.init() ;
while( cin >> op ) {
if( !op ) {
break ;
} else if( op == ) {
cin >> x >> y ;
T.insert( T.root , y , x ) ;
} else if( op == ) {
x = T.Find_max( T.root ) ;
if( x == - ) { cout << '' << endl ; continue ; }
T.remove( T.root , x ) ;
} else {
x = T.Find_min( T.root ) ;
if( x == - ) { cout << '' << endl ; continue ; }
T.remove( T.root , x ) ;
}
}
return ;
}
int main () {
ios::sync_with_stdio();
return Run() ;
}

Treap

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int N = ;
const int M = ;
int mp[M];
struct node {
int lr , rr , siz , v ;
node(){}
node( int lr , int rr , int siz , int v ):lr(lr),rr(rr),siz(siz),v(v){}
};
struct SBT {
node e[N] ;
int rt , tot;
void init() { rt = tot = ; }
void Rot_l( int &o ) {
int y = e[o].rr ;
e[o].rr = e[y].lr;
e[y].lr = o ;
e[y].siz = e[o].siz ;
e[o].siz = e[ e[o].lr ].siz + e[ e[o].rr ].siz + ;
o = y ;
}
void Rot_r( int &o ) {
int y = e[o].lr ;
e[o].lr = e[y].rr ;
e[y].rr = o ;
e[y].siz = e[o].siz ;
e[o].siz = e[ e[o].lr ].siz + e[ e[o].rr ].siz + ;
o = y ;
}
void Maintain( int &o , bool flag ) {
if( !flag ) {
if( e[ e[ e[o].lr ].lr ].siz > e[ e[o].rr ].siz ) {
Rot_r(o) ;
} else if( e[ e[ e[o].lr ].rr ].siz > e[ e[o].rr ].siz ) {
Rot_l( e[o].lr ) ;
Rot_r(o);
} else return ;
} else {
if( e[ e[ e[o].rr ].rr ].siz > e[ e[o].lr ].siz ) {
Rot_l(o) ;
} else if( e[ e[ e[o].rr ].lr ].siz > e[ e[o].lr ].siz ) {
Rot_r( e[o].rr ) ;
Rot_l(o);
} else return ;
}
Maintain( e[o].lr , false ) ;
Maintain( e[o].rr , true ) ;
Maintain( o , false ) ;
Maintain( o , true ) ;
}
void Insert( int &o , int v ) {
if( !o ) {
o = tot++ ;
e[o] = node( , , , v ) ;
return ;
} else {
e[o].siz++ ;
if( v < e[o].v ) {
Insert( e[o].lr , v ) ;
} else {
Insert( e[o].rr , v ) ;
}
}
Maintain(o, v >= e[o].v ) ;
}
void Delete( int &o , int v ) {
if( !o ) return ;
e[o].siz-- ;
if( v < e[o].v ) Delete( e[o].lr , v ) ;
else if( v > e[o].v ) Delete( e[o].rr , v ) ;
else {
if( e[o].lr == ) o = e[o].rr ;
else if( e[o].rr == ) o = e[o].lr ;
else {
int y = e[o].rr ;
while( e[y].lr ) y = e[y].lr ;
e[o].v = e[y].v ;
Delete( e[o].rr , e[y].v ) ;
}
}
}
int Find_Max( int &o ) {
int y = o ;
while( e[y].rr ) y = e[y].rr ;
return e[y].v ;
}
int Find_Min( int &o ) {
int y = o ;
while( e[y].lr ) y = e[y].lr ;
return e[y].v ;
}
} T ;
int Run() {
int op , x , y ; T.init();
while( cin >> op ) {
if( op == ) break ;
else if( op == ) {
cin >> x >> y ;
mp[y] = x ;
T.Insert( T.rt , y ) ;
} else if( op == ) {
if( T.e[T.rt].siz == ) {
cout << '' << endl ;
} else {
int v = T.Find_Max( T.rt ) ;
cout << mp[v] << endl ;
T.Delete(T.rt,v);
}
} else {
if( T.e[T.rt].siz == ) {
cout << '' << endl ;
} else {
int v = T.Find_Min( T.rt );
cout << mp[v] << endl ;
T.Delete(T.rt,v);
}
}
}
return ;
}
int main()
{
#ifdef LOCAL
freopen("in","r",stdin);
#endif
ios::sync_with_stdio();
return Run();
}

Size Balance Tree

二叉堆

const int N =  ;
int h[N] , size ;
void Modify( int p ) {
if( p == ) return ;
if( h[p>>] > h[p] ) swap( h[p>>] , h[p] ) , Modify( p>> ) ;
} void Update( int p ) {
int l = p<< , r = p<<| , f = p ;
if( l <= size && h[l] < h[f] ) f = l ;
if( r <= size && h[r] < h[f] ) f = r ;
if( p != f ) swap( h[f] , h[p] ) , Update(f) ;
} void Pop() {
swap( h[] , h[size--] ) ; Update() ;
} void Push( int x ) {
h[++size] = x ; Modify( size ) ;
}

左偏树

最大优先 ~ 可合并堆

const int N =  ;
struct node {
int lr , rr , dis , fa , val ;
} T[N] ; inline int find( int k ) { return k == T[k].fa ? k : T[k].fa = find(T[k].fa) ; } int Merge( int a , int b ) {
if( !a ) return b ;
if( !b ) return a ;
if( T[a].val < T[b].val ) swap( a , b ) ;
T[a].rr = Merge( b , T[a].rr ) ;
T[ T[a].rr ].fa = a ;
if( T[ T[a].lr ].dis < T[ T[a].rr ].dis ) swap( T[a].lr , T[a].rr ) ;
if( T[a].rr == ) T[a].dis = ;
else T[a].dis = T[ T[a].rr ].dis + ;
return a ;
} int Pop( int a ) {
int l = T[a].lr , r = T[a].rr ;
T[l].fa = l , T[r].fa = r ;
T[a].lr = T[a].rr = T[a].dis = ;
return Merge( l , r ) ;
}

最短路( Dij , Spfa )

匈牙利

HK

带花树

Dinic

const int N = ;
const int M = ;
const int inf = 1e9 ; int s , t , n , m ;
int eh[N] , ef[M] , et[M] , ec[M] , nxt[M] , tot ;
int cur[N] , d[N] ;
bool vis[N] ; void init() {
memset( eh , - , sizeof eh ) ;
tot = ;
}
void addedge( int u , int v, int c , int f ) {
et[tot] = v , ec[tot] = c , ef[tot] = f , nxt[tot] = eh[u] , eh[u] = tot++ ;
et[tot] = u , ec[tot] = , ef[tot] = f , nxt[tot] = eh[v] , eh[v] = tot++ ;
} bool bfs() {
memset( vis , false , sizeof vis ) ;
queue<int>que;
que.push(s);
vis[s] = true ;
d[s] = ;
while( !que.empty() ) {
int u = que.front() ; que.pop() ;
for( int i = eh[u] ; ~i ; i = nxt[i] ) {
int v = et[i] ;
if( !vis[v] && ef[i] < ec[i] ) {
vis[v] = true ;
d[v] = d[u] + ;
que.push(v);
}
}
}
return vis[t] ;
} int dfs( int x , int a ) {
if( x == t || a == ) return a ;
int flow = , F ;
for( int &i = cur[x] ; ~i ; i = nxt[i] ) {
int v = et[i] , c = ec[i] , &f = ef[i] ;
if( d[x] + == d[v] && ( F = dfs( v , min( a , c - f ) ) ) > ) {
f += F , ef[i^] -= F , a -= F , flow += F ;
if( a == ) break ;
}
}
return flow ;
} int MF() {
int flow = ;
while( bfs() ) {
memcpy( cur , eh , sizeof eh ) ;
flow += dfs( s , );
}
return flow ;
}

ISAP

const int N =  ;
const int M = ;
const int INF = 0x3f3f3f3f;
int n , m , s , t ;
int eh[N] , et[M] , nxt[M] , ef[M] , ec[M] , tot ; void init() {
memset( eh , - , sizeof eh ) ;
tot = ;
} void addedge( int u , int v , int c ) {
et[tot] = v ; ec[tot] = c ; ef[tot] = ; nxt[tot] = eh[u] ; eh[u] = tot++;
et[tot] = u ; ec[tot] = ; ef[tot] = ; nxt[tot] = eh[v] ; eh[v] = tot++;
} int d[N] , cur[N] , pre[N] , gap[N] ;
int Q[M] , S[M] ; void bfs() {
memset( d , - , sizeof d ) ;
memset( gap , , sizeof gap ) ;
int head = , tail = ;
d[t] = ; gap[]++ ;
Q[tail++] = t ;
while( head < tail ) {
int u = Q[head++] ;
for( int i = eh[u] ; ~i ; i = nxt[i] ) {
int v = et[i] ;
if( d[v] != - ) continue ;
Q[tail++] = v ;
d[v] = d[u] + ;
gap[ d[v] ]++;
}
}
} int Sap( int n ) {
bfs();
memcpy( cur , eh , sizeof eh ) ;
int top = , u = s , flow = ;
while( d[s] < n ) {
if( u == t ) {
int Min = INF , inser ;
for( int i = ; i < top ; ++i ) {
if( Min > ec[ S[i] ] - ef[ S[i] ] ) {
Min = ec[ S[i] ] - ef[ S[i] ] ;
inser = i ;
}
}
for( int i = ; i < top ; ++i ) {
ef[ S[i] ] += Min ;
ef[ S[i]^ ] -= Min ;
}
flow += Min ;
top = inser ;
u = et[ S[top]^ ];
continue ;
}
bool flag = false ;
int v ;
for( int i = cur[u] ; ~i ; i = nxt[i] ) {
v = et[i] ;
if( ec[i] > ef[i] && d[v] + == d[u] ) {
flag = true ;
cur[u] = i ;
break ;
}
}
if( flag ) {
S[top++] = cur[u] ;
u = v ;
continue ;
}
int Min = n ;
for( int i = eh[u] ; ~i ; i = nxt[i] ) {
if( ec[i] > ef[i] && d[ et[i] ] < Min ) {
Min = d[ et[i] ] ;
cur[u] = i ;
}
}
gap[ d[u] ]-- ;
if( !gap[ d[u] ] ) return flow ;
d[u] = Min + ;
gap[ d[u] ]++ ;
if( u != s ) u = et[ S[--top]^ ] ;
}
return flow ;
}

MCMF

const int N = ;
const int M = ;
const int INF = 0x3f3f3f3f; int eh[N] , ec[M] , et[M] , ef[M] , ew[M] , nxt[M] , tot ;
int pre[N] , dis[N] ;
bool vis[N] ;
int s , t , n , m , k ;
void init() {
memset( eh, - , sizeof eh );
tot = ;
}
void addedge( int u , int v , int cap , int cost ) {
et[tot] = v ; ef[tot] = ; ec[tot] = cap ; ew[tot] = cost ; nxt[tot] = eh[u] ; eh[u] = tot++ ;
et[tot] = u ; ef[tot] = ; ec[tot] = ; ew[tot] = -cost ; nxt[tot] = eh[v] ; eh[v] = tot++ ;
} bool spfa() {
memset( vis, false, sizeof vis ) ;
memset( dis ,0x3f , sizeof dis ) ;
memset( pre , - ,sizeof pre ) ;
queue<int>que;
dis[s] = ;
vis[s] = true ;
que.push(s) ;
while( !que.empty() ) {
int u = que.front() ; que.pop() ;
vis[u] =false ;
for( int i = eh[u] ; ~i ; i = nxt[i] ) {
int v = et[i] ;
if( ec[i] > ef[i] && dis[v] > dis[u] + ew[i] ) {
dis[v] = dis[u] + ew[i] ;
pre[v] = i ;
if( !vis[v] ) {
vis[v] = true ;
que.push(v) ;
}
}
}
}
return pre[t] != - ;
} int MCMF( int &cost ) {
int flow = ;
cost = ;
while( spfa() ) {
int Min = INF ;
for( int i = pre[t] ; ~i ; i = pre[ et[i^] ] ) {
if( Min > ec[i] - ef[i] ) {
Min = ec[i] - ef[i] ;
}
}
for( int i = pre[t] ; ~i ; i = pre[ et[i^] ] ) {
ef[i] += Min ;
ef[i^] -= Min ;
cost += ew[i] * Min ;
}
flow += Min ;
}
return flow ;
}

BCC

SCC

KMP

Manancher

AC自动机

后缀数组

后缀自动机

DXL(精确覆盖,模糊覆盖)

SCAU_WeiShenWahle 之省赛任务的更多相关文章

  1. SCNU ACM 2016新生赛决赛 解题报告

    新生初赛题目.解题思路.参考代码一览 A. 拒绝虐狗 Problem Description CZJ 去排队打饭的时候看到前面有几对情侣秀恩爱,作为单身狗的 CZJ 表示很难受. 现在给出一个字符串代 ...

  2. SCNU ACM 2016新生赛初赛 解题报告

    新生初赛题目.解题思路.参考代码一览 1001. 无聊的日常 Problem Description 两位小朋友小A和小B无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...

  3. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  4. SCNU 2015ACM新生赛决赛【F. Oyk闯机关】解题报告

            题目大意:一个$N$$\times$$N$的阵列,每个格子有$X_{ij}$个调和之音,若每次只能选择走右边或下边,从左上角出发走到右下角,问最多能收集到多少个调和之音?       ...

  5. SCNU 2015ACM新生赛初赛【1007. ZLM的扑克牌】解题报告

            题目链接详见SCNU 2015新生网络赛 1007. ZLM的扑克牌 .         其实我在想这题的时候,还想过要不要设置求最小的排列,并且对于回文数字的话,可以把扑克牌折起来( ...

  6. SCNU 2015ACM新生赛初赛【1006. 3D打印】解题报告

            题目链接详见SCNU 2015新生网络赛 1006. 3D打印 .出题思路来自codevs 3288. 积木大赛,属于模拟题.         首先我们把“选择从第L部分到第R部分”理 ...

  7. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  8. NOIP模拟赛20161022

    NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...

  9. 第七届山东省ACM省赛

    激动人心的省赛终于结束了…平静下来再回头看真的感觉一波三折…先是赛前毫无预兆的查出突发性耳聋…伴随而来的就是左耳听力下降.轻微耳鸣.极个别情况下的头晕…不过这都还好,毕竟药物可以恢复…热身赛只过了一道 ...

随机推荐

  1. 小程序获取Unionid

    小程序获取用户Unionid,必须授权获取密文.但授权成功后不是永久的.除非关注了公众号或者App微信绑定了, 解决办法是通过code获取openid,然后用openid去数据库查对应的Unionid ...

  2. 实战build-react(一)

    https://www.jianshu.com/p/34468f13263c(copy)  目录结构 一.安装 npm install -g create-react-app 二.创建react应用 ...

  3. 牛客网 Chess ( 博弈 && 奇异局势 )

    题目链接 分析 : 发现如果一开始就在边界或者位于对角线的位置上肯定是必胜态 从终点逆推,画出胜负表格,填一填,就会发现和奇异局势的前几项一样 然后打个奇异局势的表就能 AC 了 #include&l ...

  4. 3D Computer Grapihcs Using OpenGL - 18 相机移动

    移动相机需要用到键盘按键,按键事件的引入需要包含头文件 #include <Qt3DInput\qkeyevent.h> 并实现QWidget中定义的虚函数keyPressEvent 我们 ...

  5. Sql 中的as是什么意思 + 无列名注入解析

    相当于取别名 这里结合一下无列名注入的知识点: 这种方法在第十届SWPUCTF的web1——广告招租里考到了:

  6. Java第一次学习总结

    学习内容: 1.java是本学期刚刚接触新的一种编程语言,与大一C语言在语法上有很多相同之处,不同的是在很多问题上,更加简练,更加易于理解. 例如:输出水仙花数,从C语言近五十行代码缩短近十几行,数据 ...

  7. leetcode-mid-backtracking-17. Letter Combinations of a Phone Number

    mycode  68.26% class Solution(object): def letterCombinations(self, digits): """ :typ ...

  8. 数据结构和算法(Java版)快速学习(交换、选择、插入排序)

    基本排序算法:交换.选择.插入排序 常用的交换排序又称之为:冒泡排序 一般河水中的冒泡,水底刚冒出来的时候是比较小的,随着慢慢向水面浮起会逐渐增大,冒泡排序由此物理规律得来. 冒泡算法的运作规律如下: ...

  9. 我写过的bug...

    添加对,更新和查询出错 因为只写了bean里只写了se't方法,没有写get 多条件联合查询,后一个条件没用 写xml里面复制上一行,忘记把变量名改了(propertyValue没改成register ...

  10. java数字加密算法

    数字加密在项目中时常会遇到,如手机号,身份证号信息等,下面小白将自己手写的数字加密算法分享给大家,可在项目中直接运用.加密规则,入参时传递一个字段时间戳 time:* 1.以字母代替数字,0-9分别为 ...