点双

注意两个点,特判单点,是 son = 0fa = 0,因为自环,还有弹栈弹到儿子节点处,因为点双不一定由割点弹出。

code
void dfs(int u, int la) {
int son = 0;
low[u] = dfn[u] = ++ dfc;
sta[++ top] = u;
for(int v : A[u]) {
if(!dfn[v]) {
++ son;
dfs(v, u);
cmin(low[u], low[v]);
if(low[v] >= dfn[u]) {
++ scc;
while(true) {
int cur = sta[top];
S[scc].eb(cur);
-- top;
if(cur == v) break;
// 为什么不能用 cur == u 的写法,因为当前点不一定是本割点的出点,8 型
}
}
}
else if(v != la) cmin(low[u], dfn[v]);
}
if(la == 0 && son == 0) S[++ scc].eb(u);
} void tarjan() {
rep(i, 1, n) {
if(!dfn[i]) {
top = 0;
dfs(i, 0);
}
}
}

边双

可以用 pii 存边,注意是边不能走反向,即重边。

code
void dfs(int u, int la) {
stk[++ top] = u;
dfn[u] = low[u] = ++ dfc;
for(pii e : A[u]) {
if(e.fi == la) continue;
int v = e.se;
if(dfn[v]) cmin(low[u], dfn[v]);
else dfs(v, e.fi), cmin(low[u], low[v]);
}
if(dfn[u] != low[u]) return;
++ scc;
while(true) {
int cur = stk[top]; -- top;
S[scc].eb(cur);
if(cur == u) break;
}
} void tarjan() {
rep(i, 1, n) {
if(!dfn[i]) {
dfs(i, -1);
}
}
}

割点

注意根节点的判断。

code
void dfs(int u, int la) {
int son = 0;
dfn[u] = low[u] = ++ dfc;
for(int v : A[u]) {
if(v == la) continue;
if(dfn[v]) cmin(low[u], dfn[v]);
else {
++ son;
dfs(v, u);
cmin(low[u], low[v]);
if(low[v] >= dfn[u]) {
cut[u] = 1;
}
}
}
if(son == 1 && la == 0) cut[u] = 0;
} void tarjan() {
rep(i, 1, n) {
if(dfn[i]) continue;
dfs(i, 0);
}
}

割边

这个好像没有例题?

强连通分量

圆方树

看着 OI-Wiki 打了个板子。

code

```cpp
void dfs(int u) {
low[u] = dfn[u] = ++ dfc;
stk[++ tp] = u;
for(int v : G[u]) {
if(!dfn[v]) {
dfs(v);
cmin(low[u], low[v]);
if(low[v] == dfn[u]) {
++ cnt;
for(int x = 0; x != v; -- tp) {
x = stk[tp];
T[cnt].eb(x);
T[x].eb(cnt);
}
T[cnt].eb(u);
T[u].eb(cnt);
}
}
else cmin(low[u], dfn[v]);
}
}

void solve() {

rd(n, m);

rep(i, 1, m) {

int u, v;

rd(u, v);

G[u].eb(v);

G[v].eb(u);

}

cnt = n;

rep(u, 1, n) if(!dfn[u]) dfs(u), -- tp;

rep(i, n + 1, cnt) {

printf("#id = %d, #size = %d, include:", i - n, (int) T[i].size());

for(int j : T[i]) {

printf("%d ", j);

}

puts("");

}

return;

}


</details> ## 铁人两项
[LUOGU](https://www.luogu.com.cn/problem/P4630)
[LOJ](https://loj.ac/p/2587) 还是照着 OI-Wiki 打了个板子。这个赋点权的方法很厉害啊。 <details>
<summary>code</summary> ```cpp
void dfs(int u) {
low[u] = dfn[u] = ++ dfc;
stk[++ tp] = u;
++ num;
for(int v : G[u]) {
if(!dfn[v]) {
dfs(v);
cmin(low[u], low[v]);
if(low[v] == dfn[u]) {
++ cnt;
for(int x = 0; x != v; -- tp) {
x = stk[tp];
T[cnt].eb(x);
T[x].eb(cnt);
}
T[cnt].eb(u);
T[u].eb(cnt);
val[cnt] = T[cnt].size();
}
}
else cmin(low[u], dfn[v]);
}
}
void dfs1(int u, int la) {
vis[u] = 1;
sz[u] = (u <= n);
for(int v : T[u]) {
if(v == la) continue;
dfs1(v, u);
ans += 2LL * val[u] * sz[u] * sz[v];
sz[u] += sz[v];
}
ans += 2LL * val[u] * sz[u] * (num - sz[u]);
}
void solve() {
rd(n, m);
rep(i, 1, n) {val[i] = -1;}
rep(i, 1, m) {
int u, v;
rd(u, v);
G[u].eb(v);
G[v].eb(u);
}
cnt = n;
rep(u, 1, n) {
if(!dfn[u]) {
num = 0;
dfs(u);
-- tp;
dfs1(u, 0);
}
}
printf("%lld\n", ans);
return;
}

网络流

树链剖分

LCT

主席树

分块

莫队

  • 带修莫队

  • 回滚莫队/不删除莫队

  • 树上莫队

平衡树

  • FHQ Treap

  • Splay

旋转卡壳

打的也不是板子,是 这题

code
ll dist(int i1, int i2) {
return 1LL * (p[i1].x - p[i2].x) * (p[i1].x - p[i2].x) + 1LL * (p[i1].y - p[i2].y) * (p[i1].y - p[i2].y);
}
ll cross(int p0, int p1, int p2) {
return 1LL * (p[p1].x - p[p0].x) * (p[p2].y - p[p0].y) - 1LL * (p[p2].x - p[p0].x) * (p[p1].y - p[p0].y);
}
void In(int a, int b) {
pq.push(dist(a, b));
if((int) pq.size() > k) pq.pop();
}
bool cmp(int a, int b) {
return p[a].x == p[b].x ? p[a].y < p[b].y : p[a].x < p[b].x;
}
int nxt(int x) {return x % top + 1;}
pii calc() {
o_n = 0;
rep(i, 1, n) {
if(!vis[i]) {
o[++ o_n] = i;
}
}
sort(o + 1, o + o_n + 1, cmp);
sta[top = 1] = o[1];
rep(i, 2, o_n) {
while(top > 1 && cross(sta[top - 1], sta[top], o[i]) <= 0) {
-- top;
}
sta[++ top] = o[i];
}
int pre = top;
per(i, o_n - 1, 1) {
while(top > pre && cross(sta[top - 1], sta[top], o[i]) <= 0) {
-- top;
}
sta[++ top] = o[i];
}
-- top;
if(top == 2) return mp(sta[1], sta[2]);
// 前面都是求凸包模板
// 接下来是找直径模板
int cur = 1;
while(cross(sta[top], sta[1], sta[nxt(cur)]) > cross(sta[top], sta[1], sta[cur])) {
cur = nxt(cur);
}
int a = sta[cur], b;
if(dist(sta[cur], sta[1]) > dist(sta[cur], sta[top])) b = sta[1];
else b = sta[top];
// 找以 sta[1], sta[top] 这条边为对边的对踵点
// 一个个找,比较
rep(i, 1, top - 1) {
while(cross(sta[i], sta[i + 1], sta[nxt(cur)]) > cross(sta[i], sta[i + 1], sta[cur])) {
cur = nxt(cur);
}
// 两个都要比较一下
if(dist(sta[cur], sta[i]) > dist(a, b)) {
a = sta[cur];
b = sta[i];
}
if(dist(sta[cur], sta[i + 1]) > dist(a, b)) {
a = sta[cur];
b = sta[i + 1];
}
}
return mp(a, b);
}
void solve() {
rd(n, k);
// printf("%d %d\n", n, k);
rep(i, 1, n) {
rd(p[i].x, p[i].y);
}
rep(i, 1, min(k, n / 2)) {
pii res = calc();
// 处理的是凸包
// 将凸包上所有距离较远的加入
int a = res.fi;
int b = res.se;
In(a, b);
vis[a] = vis[b] = 1;
rep(j, 1, n) {
if(!vis[j]) {
In(a, j);
In(b, j);
}
}
}
printf("%lld", pq.top());
}

点分治

李超线段树

code

NOIP 考前板子复习的更多相关文章

  1. NOIP 考前 队列复习

    BZOJ 1127 #include <cstdio> #include <cstring> #include <iostream> #include <al ...

  2. NOIP 考前 数论复习

    POJ 2891 x=r1 (mod a1) x=r2 (mod a2) x=a1*x+r1,x=a2*y+r2; a1*x-a2*y=r2-r1; 用Extend_Gcd求出m1*x+m2*y=d; ...

  3. NOIP 考前 数据结构复习

    BZOJ 1455 左偏树即可 #include <cstdio> #define LL long long ; struct Info{LL l,r,v,Dis;}Tree[Maxn]; ...

  4. NOIP 考前DP 复习

    POJ 2533 最长不降子序列 #include <cstdio> ; int a[Maxn],Pos[Maxn],F[Maxn],n,Ans; inline int Max(int x ...

  5. NOIP 考前 Tarjan复习

    POJ 1236 给定一个有向图,求: 1) 至少要选几个顶点,才能做到从这些顶点出发,可以到达全部顶点 2) 至少要加多少条边,才能使得从任何一个顶点出发,都能到达全部顶点 第一个就是缩点之后有多少 ...

  6. noip考前模板复习

    网络流 Dinic(搭配飞行员) //Serene #include<algorithm> #include<iostream> #include<cstring> ...

  7. Noip前的大抱佛脚----Noip真题复习

    Noip前的大抱佛脚----Noip真题复习 Tags: Noip前的大抱佛脚 Noip2010 题目不难,但是三个半小时的话要写四道题还是需要码力,不过按照现在的实力应该不出意外可以AK的. 机器翻 ...

  8. NOIP考前划水

    NOIP考前划水 君指先跃动の光は.私の一生不変の信仰に.唯私の超電磁砲永世生き! 要开始背配置了? 3行不谢. (setq c-default-style "awk") (glo ...

  9. NOIP 考前 并查集复习

    POJ 1182 把一个点拆成x,x+n,x+2*n,x吃y可以表示认为x,y+n是一类的,x+n,y+2*n是一类,x+2*n,y是一类. #include <cstdio> ; ],n ...

  10. NOIP考前复习-数制转换,数论模板与文件读写

    数制转换有两种题型,一般一题,分值1.5分. 题型一:R进制转十进制 解法就是:按权展开,但要注意各个位的权,最低位(最右边)的权是0次方,权值为1. 纯整数的情况: (11010110)2 = 1× ...

随机推荐

  1. Luogu P5745 区间最大和

    原题链接:Luogu P5745 区间最大和 初看这道题,

  2. [oeasy]python0123_中文字符_文字编码_gb2312_激光照排技术_王选

    中文编码GB2312 回忆上次内容 上次回顾了 日韩各有 编码格式 日本 有假名 五十音 一字节 可以勉强放下   有日本汉字 字符数量超过20000+     韩国 有谚文 数量超过500 一个字节 ...

  3. [oeasy]python0094_视频游戏_双人网球_pong_atari_mos_6502_雅达利_米洛华

    编码进化 回忆上次内容 上次 我们回顾了 微软之前的 比尔盖茨和保罗艾伦 mits 迎来的 是帮手 还是隐患? intel-8080 遇到了 mos-6502 底层硬件 驱动 游戏行业进化 不光是扑克 ...

  4. Less预处理器的使用

    练习页面: <body> <div class="div1"> <div class="div2"></div> ...

  5. Vue入门记录(一)

    效果 本文为实现如下前端效果的学习实践记录: 实践 入门的最佳实践我觉得是先去看官网,官网一般都会有快速入门指引. 根据官网的快速上手文档,构建一个新的Vue3+TypeScript,查看新建的项目结 ...

  6. BCLinux 8.2安装配置图解教程--龙蜥社区国产移动云系统

    社区镜像下载地址:https://openanolis.cn/download 安装参考地址:https://www.osyunwei.com/archives/13017.html 1安装系统 界面 ...

  7. 对比python学julia(第三章:游戏编程)--(第二节)公主迎圣诞(4)

    4.  碰撞检测 .得分及生命 在第 4 个阶段,利用GameZero的碰撞检测功能,使公主角色能够接到雪花 .礼物或剪刀. 在"sdgz"项目目录中 ,把 version3.jl ...

  8. 【MySQL】Navicat踩坑:Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT) for operation 'instr'

    在Navicat客户端上面执行SQL报错 SQL语句: WITH RECURSIVE transfer (start_station, stop_station, stops, path) AS ( ...

  9. 【RabbitMQ】06 Spring整合RabbitMQ

    首先生产者和消费者需要的Maven依赖是一样的 <?xml version="1.0" encoding="UTF-8"?> <project ...

  10. 【perl】01

    1.环境搭建 -- 解释器 / 编译器 Perl 在 Window 平台上有 ActiveStatePerl 和 Strawberry Perl 编译器. ActiveState Perl和 Stra ...