Skip to content

Commit 1ee8674

Browse files
committed
发布第一版成品
1 parent f27b9ac commit 1ee8674

26 files changed

Lines changed: 1277 additions & 28 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.exe
22
*.pdf
3+
*.log
34
.vscode/
45
code/.vscode/

README.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,44 @@
1-
正文源码在 `template.md` 文件中
1+
**当前最新版本为 `v1.0.0`** (总词数约7.7w(含代码))
22

3-
> 推荐编辑/阅读该文件所用工具为 Typora beta 0.11.17
3+
成品为 `template.pdf` (移步 [releases](https://github.com/lr580/algorithm_template/releases) 查看/下载)
44

5-
成品为 `template.pdf` (移步 [releases](https://github.com/lr580/algorithm_template/releases) 查看)(目前未有成品)
5+
<hr/>
66

7-
部分代码源码在 `codes/`
7+
## 模板简介
88

9-
预计不晚于 4-10 完工第一版
9+
这是一份适用于算法竞赛的 C++ 为主的代码模板集合。主要用作 ICPC区域赛/CCPC 比赛时的参考资料,可打印。本模板收录大部分铜牌算法和银牌算法,不收录过于基础的内容(如栈),也不收录过难的内容(如广义后缀自动机)。不定期更新。
1010

11-
<hr/>
11+
本模板主要浓缩提炼自我的算法笔记(三份笔记,折合约28.5万+2.5万+5万=36万字(含代码)),历时约两周爆肝制成,因时间仓促,难免可能产生纰漏,如果您发现了任何错误之处或者如果您对本模板的内容增删改有任何意见或建议,欢迎您随时提出 >_<
1212

13-
## 模板简介
13+
> 目前版本使用 Typora 制作,有生之年有概率考虑使用 LaTeX 重做本模板。碍于本人技术有限,目前目录页码是手动制作的,因此可能会出现页码不正确,若发现欢迎纠正
14+
15+
目前模板收录的模块大致如下:(具体请参见详细目录)
16+
17+
1. 数学
1418

15-
这是一份适用于算法竞赛的 C++ 为主的代码模板集合。主要使用于 ICPC区域赛/CCPC 作比赛时参考资料,可打印,收录铜牌算法和银牌算法,可能不收录过于基础的内容,也不收录过难的内容。不定期更新。
19+
主要含组合数学、数论、计算几何、博弈论等
1620

17-
本模板主要浓缩提炼自我的算法笔记(三份笔记,折合约28.5万+2.5万+5万=36万字(含代码)),因时间仓促,难免可能产生纰漏,如果您发现了任何错误之处或者如果您对本模板的内容增删改有任何意见或建议,欢迎您随时提出 >_<
21+
2. 数据结构
1822

19-
> 目前版本使用 Typora 生成,有生之年也许考虑使用 LaTeX 重做本模板。碍于本人技术有限,目前目录页码是手动制作的,因此可能会出现页码不正确 //欢迎纠正
23+
3. 图论
2024

25+
主要含树上问题、图论基础、二分图、网络流等
2126

27+
4. 动态规划
2228

23-
## 模板目录
29+
5. 字符串
2430

25-
暂时请参见 `template.md` ,稍后补充在此
31+
6. 杂项
32+
33+
主要含排序、二分、搜索、高精度、STL等
34+
35+
正文源码在 `template.md` 文件中
36+
37+
> 推荐编辑/阅读该源码文件所用工具为 Typora beta 0.11.17
38+
39+
> 部分代码源码在 `codes/`
40+
41+
<s>Starred it to keep trace of any possible updates!</s>
2642

2743

2844

@@ -57,4 +73,8 @@
5773
- 补充了数论、高等数学、杂项内容
5874
- 增加了博弈论、字符串、计算几何、线性代数和概率论、动态规划内容
5975

76+
- 22/04/04
77+
- 稍微补充了少量内容
78+
- 发布了第一版模板 (`v1.0.0`)
79+
6080

code/LCS.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define sc(x) scanf("%lld", &x)
4+
typedef long long ll;
5+
#define N 1024
6+
int c[N+1][N+1];//c[i][j]代表Xi与Yj的LCS长度
7+
int lcs(string X, string Y)
8+
{
9+
int m = X.size();
10+
int n = Y.size();
11+
int maxl = 0;
12+
X = ' ' + X;
13+
Y = ' ' + Y;
14+
for(int i=1;i<=m;i++) c[i][0] = 0;
15+
for(int j=1;j<=n;j++) c[0][j] = 0;
16+
for(int i=1;i<=m;i++)
17+
{
18+
for(int j=1;j<=n;j++)
19+
{
20+
if(X[i]==Y[j]) c[i][j] = c[i-1][j-1] + 1;
21+
else c[i][j] = max(c[i-1][j], c[i][j-1]);
22+
maxl = max(maxl, c[i][j]);
23+
}
24+
}
25+
return maxl;
26+
}

code/atc122d_dp.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include <iostream>
2+
#define maxn 105
3+
using namespace std;
4+
typedef long long ll;
5+
6+
ll dp[maxn][4][4][4];
7+
const ll MOD = 1e9 + 7;
8+
bool check(int j, int k, int v)
9+
{
10+
return !(j == 0 && k == 2 && v == 1);
11+
}
12+
bool check2(int j, int k, int v)
13+
{
14+
// 0->a, 1->c, 2->g, 3->t
15+
if (!((j == 0 && k == 2 && v == 1) || (j == 0 && k == 1 && v == 2) || (j == 2 && k == 0 && v == 1)))
16+
return true;
17+
return false;
18+
}
19+
20+
int main()
21+
{
22+
int n;
23+
cin >> n;
24+
25+
for (int j = 0; j < 4; j++)
26+
{
27+
for (int k = 0; k < 4; k++)
28+
{
29+
for (int v = 0; v < 4; v++)
30+
{
31+
if (check2(j, k, v))
32+
dp[3][j][k][v] = 1;
33+
}
34+
}
35+
}
36+
37+
for (int i = 4; i <= n; i++)
38+
{
39+
for (int j = 0; j < 4; j++)
40+
{
41+
for (int k = 0; k < 4; k++)
42+
{
43+
for (int v = 0; v < 4; v++)
44+
{
45+
for (int u = 0; u < 4; u++)
46+
if (check2(j, k, v) && check(u, k, v) && check(u, j, v) && check(u, j, k))//最后一个check没有也行;因为这种情况下原dp[i-1][u][j][k]就是0
47+
dp[i][j][k][v] = (dp[i][j][k][v] + dp[i - 1][u][j][k]) % MOD;
48+
}
49+
}
50+
}
51+
}
52+
53+
ll ans = 0;
54+
for (int i = 0; i < 4; i++)
55+
for (int j = 0; j < 4; j++)
56+
for (int k = 0; k < 4; k++)
57+
ans = (ans + dp[n][i][j][k]) % MOD;
58+
59+
cout << ans << endl;
60+
return 0;
61+
}

code/edit_distance.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define MAXN 2002
4+
#define repe(i,a,b) for(int i=a;i<=b;++i)
5+
int n,dp[MAXN][MAXN];
6+
char x[MAXN],y[MAXN];
7+
int edit(int a, int b)
8+
{
9+
if(dp[a][b]!=-1) return dp[a][b];
10+
if(!a) return dp[a][b]=b;
11+
if(!b) return dp[a][b]=a;
12+
return dp[a][b]=min(min(edit(a-1,b)+1,edit(a,b-1)+1),edit(a-1,b-1)+(int)(x[a]!=y[b]));
13+
}
14+
signed main()
15+
{
16+
scanf("%s%s",x+1,y+1);
17+
repe(i,0,2000) repe(j,0,2000) dp[i][j]=-1;
18+
printf("%d", edit(strlen(x+1),strlen(y+1)));
19+
return 0;
20+
}

code/geometry.cpp

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define sc(x) scanf("%lld", &x)
4+
typedef long long ll;
5+
#define EPS (1e-10)
6+
#define equals(a, b) (fabs((a) - (b)) < EPS)
7+
class Point
8+
{
9+
public:
10+
double x, y;
11+
Point(double x = 0, double y = 0) : x(x), y(y) {}
12+
Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); }
13+
Point operator-(const Point &p) const { return Point(x - p.x, y - +p.y); }
14+
Point operator*(const double &a) const { return Point(x * a, y * a); }
15+
Point operator/(const double &a) const { return Point(x / a, y / a); }
16+
double norm() const { return x * x + y * y; }
17+
double abs() const { return sqrt(norm()); }
18+
bool operator<(const Point &p) const
19+
{
20+
return x != p.x ? x < p.x : y < p.y;
21+
}
22+
bool operator==(const Point &p) const
23+
{
24+
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
25+
}
26+
};
27+
typedef Point Vector;
28+
double dot(const Point &a, const Point &b)
29+
{
30+
return a.x * b.x + a.y * b.y;
31+
}
32+
double cross(const Point &a, const Point &b)
33+
{
34+
return a.x * b.y - a.y * b.x;
35+
}
36+
bool isParallel(const Vector &a, const Vector &b)
37+
{
38+
return equals(cross(a, b), 0.0);
39+
}
40+
bool isOrthogonal(const Vector &a, const Vector &b)
41+
{
42+
return equals(dot(a, b), 0.0);
43+
}
44+
double getDistance(const Point &a, const Point &b)
45+
{
46+
return (a - b).abs();
47+
}
48+
//极坐标互换
49+
double arg(const Vector &p) { return atan2(p.y, p.x); }
50+
Vector polar(const double &a, const double &r)
51+
{
52+
return Point(cos(r) * a, sin(r) * a);
53+
}
54+
double dis_lp(const Point &a, const Point &b, const Point &p)
55+
{
56+
return abs(cross(b - a, p - a)) / (b - a).abs();
57+
}
58+
double dis_sp(const Point &a, const Point &b, const Point &p)
59+
{
60+
if (dot(b - a, p - a) < 0.0)
61+
{
62+
return (p - a).abs();
63+
}
64+
if (dot(a - b, p - b) < 0.0)
65+
{
66+
return (p - b).abs();
67+
}
68+
return dis_lp(a, b, p);
69+
}
70+
// bool isIntersect(const Point &a, const Point &b, const Point &c, const Point &d)
71+
// {
72+
// return cross(c - a, d - a) * cross(c - b, d - b) <= 0.0 && cross(a - c, b - c) * cross(a - d, b - d) <= 0.0;
73+
// } // 条件: AB,CD不在一条直线上
74+
ll f(const Point &a, const Point &b)
75+
{
76+
if (cross(a, b) > EPS)
77+
{
78+
return 1; //逆时针
79+
}
80+
if (cross(a, b) < -EPS)
81+
{
82+
return -1; //顺时针
83+
}
84+
if (dot(a, b) < -EPS)
85+
{
86+
return 2; // P在AB左方
87+
}
88+
if (a.abs() < b.abs())
89+
{
90+
return -2; // P在AB右方
91+
}
92+
return 0; // P在AB内部
93+
}
94+
bool isIntersect(const Point &a, const Point &b, const Point &c, const Point &d)
95+
{
96+
return f(c - a, d - a) * f(c - b, d - b) <= 0 && f(a - c, b - c) * f(a - d, b - d) <= 0;
97+
}
98+
Point intersect(const Point &a, const Point &b, const Point &c, const Point &d)
99+
{
100+
return c + (d - c) * (cross(a - c, b - a) / cross(d - c, b - a));
101+
}
102+
Point project(const Point &a, const Point &b, const Point &p)
103+
{
104+
return a + (b - a) * (dot(b - a, p - a) / (b - a).norm());
105+
}
106+
signed main()
107+
{
108+
109+
return 0;
110+
}

0 commit comments

Comments
 (0)