Skip to content

Commit 930cddb

Browse files
committed
Update
1 parent 03c7d30 commit 930cddb

13 files changed

+574
-105
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## 简介
22
在本科期间,本人获得了XCPC金奖共计8枚,包括EC Final金奖和CCPC Final金奖,区域赛最好成绩为2020CCPC长春站的季军。
33
<img src="https://github.com/sunkafei/sunkafei.github.io/blob/main/cv/images/xcpc-gold-medals.png"> </img>
4-
此外还获得过CCSP 金奖,CCCC 一等奖,华为嵌入式软件大赛总决赛算法组 冠军,华为算法大赛高校组 冠军,<a href="https://codeforces.com/contest/1885/standings">ICPC 2023 Online Challenge powered by Huawei</a> 一等奖(中国区第一名,总排名第五)
4+
此外还获得过CCSP 金奖,CCCC 一等奖,华为嵌入式软件大赛算法组 冠军,华为算法大赛高校组 冠军,昇腾AI原生创新算子挑战赛 冠军,<a href="https://codeforces.com/contest/1885/standings">ICPC 2023 Online Challenge powered by Huawei</a> 一等奖。
55
<img src="https://github.com/sunkafei/sunkafei.github.io/blob/main/cv/images/other-certificates.png"> </img>
66

77
目前本人已退役,并将自己的算法模板整理如下,重点是数据结构和字符串,涉及的数论和计算几何较少(队友负责)。
@@ -22,6 +22,10 @@
2222
- 有向图的传递闭包
2323
- 最小树形图
2424
- 支配树
25+
- 强连通分量
26+
- 无向图的割顶和桥
27+
- 无向图的点双连通分量
28+
- 无向图的边双连通分量
2529
- 树算法
2630
- 限定距离的子树问题
2731
- 树的欧拉序
@@ -153,3 +157,4 @@
153157
- Adam算法
154158
- Dyna-Q
155159
- kmeans聚类
160+
- 对抗搜索(Alpha-Beta剪枝)

XCPC算法模板(2024-06-07).pdf

-1.01 MB
Binary file not shown.

XCPC算法模板(2024-12-26).pdf

763 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <vector>
2+
#include <algorithm>
3+
using namespace std;
4+
struct state {
5+
bool inFinal();
6+
int score();
7+
void expand(int, vector<state>&);
8+
};
9+
int search(state& s, int player, int alpha, int beta) {
10+
if (s.inFinal()) {
11+
return s.score();
12+
}
13+
vector<state> children;
14+
s.expand(player, children);
15+
for (auto child : children) {
16+
int value = search(child, player ^ 1, alpha, beta);
17+
if (!player) {
18+
alpha = max(alpha, value);
19+
}
20+
else {
21+
beta = min(beta, value);
22+
}
23+
if (beta <= alpha) {
24+
break;
25+
}
26+
}
27+
return !player ? alpha : beta;
28+
}

算法/图论/强连通分量.cpp

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include <vector>
2+
#include <cstdio>
3+
#include <stack>
4+
#include <ranges>
5+
#include <algorithm>
6+
using namespace std;
7+
constexpr int maxn = 11000;
8+
vector<int> G[maxn];
9+
int pre[maxn], lowlink[maxn], sccno[maxn], scc_cnt, dfs_clock;
10+
stack<int> S;
11+
void tarjan(int x) {
12+
pre[x] = lowlink[x] = ++dfs_clock;
13+
S.push(x);
14+
for (auto y : G[x]) {
15+
if (!pre[y]) {
16+
tarjan(y);
17+
lowlink[x] = min(lowlink[x], lowlink[y]);
18+
}
19+
else if (!sccno[y]) {
20+
lowlink[x] = min(lowlink[x], pre[y]);
21+
}
22+
}
23+
if (lowlink[x] == pre[x]) {
24+
scc_cnt += 1;
25+
for (;;) {
26+
int y = S.top(); S.pop();
27+
sccno[y] = scc_cnt;
28+
if (y == x) {
29+
break;
30+
}
31+
}
32+
}
33+
}
34+
void find_scc(int n) {
35+
dfs_clock = scc_cnt = 0;
36+
for (int x = 0; x <= n; ++x) {
37+
sccno[x] = pre[x] = 0;
38+
}
39+
for (int x = 1; x <= n; ++x) { //µãµÄ±àºÅ´Ó1¿ªÊ¼
40+
if (!pre[x]) {
41+
tarjan(x);
42+
}
43+
}
44+
}
45+
int main() { // Âå¹ÈB3609
46+
int n, m;
47+
scanf("%d %d", &n, &m);
48+
for (int i = 0; i < m; ++i) {
49+
int x, y;
50+
scanf("%d %d", &x, &y);
51+
G[x].push_back(y);
52+
}
53+
find_scc(n);
54+
printf("%d\n", scc_cnt);
55+
vector<int> scc[maxn];
56+
for (int i = 1; i <= n; ++i) {
57+
scc[sccno[i]].push_back(i);
58+
}
59+
for (int i = 1; i <= scc_cnt; ++i) {
60+
std::ranges::sort(scc[i]);
61+
}
62+
bool vis[maxn] {};
63+
for (int i = 1; i <= n; ++i) {
64+
if (!vis[sccno[i]]) {
65+
for (auto x : scc[sccno[i]]) {
66+
printf("%d ", x);
67+
}
68+
printf("\n");
69+
vis[sccno[i]] = true;
70+
}
71+
}
72+
return 0;
73+
}
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <cstdio>
2+
#include <vector>
3+
#include <numeric>
4+
#include <algorithm>
5+
using namespace std;
6+
constexpr int maxn = 210000;
7+
vector<int> G[maxn];
8+
int pre[maxn], iscut[maxn], dfs_clock;
9+
int dfs(int x, int fa = -1) {
10+
int lowx = pre[x] = ++dfs_clock;
11+
int child = 0;
12+
for (auto y : G[x]) {
13+
if (!pre[y]) {
14+
child += 1;
15+
int lowy = dfs(y, x);
16+
lowx = min(lowx, lowy);
17+
if (lowy >= pre[x] && fa != -1) {
18+
iscut[x] = true;
19+
}
20+
if (lowy > pre[x]) {
21+
// 边(x, y)是桥
22+
// 如果图中存在重边应当修改下面的条件:改为判断是否为反向边
23+
}
24+
}
25+
else if (y != fa) {
26+
lowx = min(lowx, pre[y]);
27+
}
28+
}
29+
if (fa == -1 && child >= 2) {
30+
iscut[x] = true;
31+
}
32+
return lowx;
33+
}
34+
void find_cut(int n) {
35+
for (int x = 0; x <= n; ++x) {
36+
pre[x] = iscut[x] = 0;
37+
}
38+
dfs_clock = 0;
39+
for (int x = 1; x <= n; ++x) { // 下标从1开始
40+
if (!pre[x]) {
41+
dfs(x, -1);
42+
}
43+
}
44+
}
45+
int main() { // 洛谷P3388
46+
//freopen("in.txt", "r", stdin);
47+
int n, m;
48+
scanf("%d %d", &n, &m);
49+
for (int i = 0; i < m; ++i) {
50+
int x, y;
51+
scanf("%d %d", &x, &y);
52+
G[x].push_back(y);
53+
G[y].push_back(x);
54+
}
55+
find_cut(n);
56+
printf("%d\n", accumulate(iscut, iscut + n + 1, 0));
57+
for (int x = 1; x <= n; ++x) if (iscut[x]) {
58+
printf("%d ", x);
59+
}
60+
printf("\n");
61+
return 0;
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <cstdio>
2+
#include <vector>
3+
#include <numeric>
4+
#include <algorithm>
5+
#include <stack>
6+
using namespace std;
7+
constexpr int maxn = 510000;
8+
vector<int> G[maxn], bcc[maxn];
9+
stack<int> S;
10+
int pre[maxn], dfs_clock, bcc_cnt;
11+
int dfs(int x, int fa = -1) {
12+
int lowx = pre[x] = ++dfs_clock;
13+
int child = 0;
14+
S.push(x);
15+
for (auto y : G[x]) {
16+
if (!pre[y]) {
17+
child += 1;
18+
int lowy = dfs(y, x);
19+
lowx = min(lowx, lowy);
20+
if (lowy >= pre[x]) { //点双联通分量
21+
bcc_cnt += 1;
22+
for (;;) {
23+
int s = S.top(); S.pop();
24+
bcc[bcc_cnt].push_back(s);
25+
if (s == y) {
26+
break;
27+
}
28+
}
29+
bcc[bcc_cnt].push_back(x);
30+
}
31+
}
32+
else if (y != fa) {
33+
lowx = min(lowx, pre[y]);
34+
}
35+
}
36+
if (fa == -1 && child == 0) { //特判独立点/单点的自环
37+
bcc[++bcc_cnt].push_back(x);
38+
}
39+
return lowx;
40+
}
41+
void find_bcc(int n) {
42+
for (int x = 0; x <= n; ++x) {
43+
pre[x] = 0;
44+
bcc[x].clear();
45+
}
46+
while (S.size()) S.pop();
47+
dfs_clock = bcc_cnt = 0;
48+
for (int x = 1; x <= n; ++x) { // 下标从1开始
49+
if (!pre[x]) {
50+
dfs(x, -1);
51+
}
52+
}
53+
}
54+
int main() { // 洛谷P8435
55+
//freopen("in.txt", "r", stdin);
56+
int n, m;
57+
scanf("%d %d", &n, &m);
58+
for (int i = 0; i < m; ++i) {
59+
int x, y;
60+
scanf("%d %d", &x, &y);
61+
G[x].push_back(y);
62+
G[y].push_back(x);
63+
}
64+
find_bcc(n);
65+
printf("%d\n", bcc_cnt);
66+
for (int i = 1; i <= bcc_cnt; ++i) {
67+
printf("%d", (int)bcc[i].size());
68+
for (auto x : bcc[i]) {
69+
printf(" %d", x);
70+
}
71+
printf("\n");
72+
}
73+
return 0;
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include <cstdio>
2+
#include <vector>
3+
#include <numeric>
4+
#include <algorithm>
5+
#include <stack>
6+
using namespace std;
7+
constexpr int maxn = 510000;
8+
vector<int> G[maxn], bcc[maxn];
9+
stack<int> S;
10+
int pre[maxn], dfs_clock, bcc_cnt;
11+
int dfs(int x, int fa = -1) {
12+
int lowx = pre[x] = ++dfs_clock;
13+
S.push(x);
14+
for (auto y : G[x]) {
15+
if (!pre[y]) {
16+
int lowy = dfs(y, x);
17+
lowx = min(lowx, lowy);
18+
}
19+
else if (y != fa) { //如果图中存在重边应当修改这个条件:改为判断是否为反向边
20+
lowx = min(lowx, pre[y]);
21+
}
22+
}
23+
if (lowx == pre[x]) {
24+
bcc_cnt += 1;
25+
for (;;) {
26+
int s = S.top(); S.pop();
27+
bcc[bcc_cnt].push_back(s);
28+
if (s == x) {
29+
break;
30+
}
31+
}
32+
}
33+
return lowx;
34+
}
35+
void find_bcc(int n) {
36+
for (int x = 0; x <= n; ++x) {
37+
pre[x] = 0;
38+
bcc[x].clear();
39+
}
40+
while (S.size()) S.pop();
41+
dfs_clock = bcc_cnt = 0;
42+
for (int x = 1; x <= n; ++x) { // 下标从1开始
43+
if (!pre[x]) {
44+
dfs(x, -1);
45+
}
46+
}
47+
}
48+
int main() { // 洛谷P8436
49+
//freopen("in.txt", "r", stdin);
50+
int n, m;
51+
scanf("%d %d", &n, &m);
52+
for (int i = 0; i < m; ++i) {
53+
int x, y;
54+
scanf("%d %d", &x, &y);
55+
G[x].push_back(y);
56+
G[y].push_back(x);
57+
}
58+
find_bcc(n);
59+
printf("%d\n", bcc_cnt);
60+
for (int i = 1; i <= bcc_cnt; ++i) {
61+
printf("%d", (int)bcc[i].size());
62+
for (auto x : bcc[i]) {
63+
printf(" %d", x);
64+
}
65+
printf("\n");
66+
}
67+
return 0;
68+
}

0 commit comments

Comments
 (0)