Skip to content

Commit 3dde468

Browse files
committed
KMP automaton + correcting some encoding problems
1 parent 7542c3e commit 3dde468

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

code/geometry/halfplaneIS.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Half plane intersection O(n*log(n))
2-
// lines must be ccw (anti-horário)
2+
// lines must be ccw (antihorario)
33

44
#include "point.h"
55
#include "lineIntersection.cpp"

code/string/kmpautomaton.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// trans = transition
2+
struct trans {
3+
int m, to[MAXN], match[MAXN];
4+
trans(int _m = -1) : m(_m) {}
5+
};
6+
7+
trans operator +(trans a, trans b) {
8+
if (b.m < 0) return a;
9+
if (a.m < 0) return b;
10+
trans c(a.m);
11+
for(int i = 0; i < c.m; i++) {
12+
c.to[i] = b.to[a.to[i]];
13+
c.match[i] = (a.match[i] + b.match[a.to[i]])%MOD;
14+
}
15+
return c;
16+
}
17+
18+
struct KMP {
19+
string P;
20+
int b[MAXN], m;
21+
void build(string &_P) {
22+
P = _P;
23+
m = P.size();
24+
memset(&b, -1, sizeof b);
25+
for(int i = 0, j = -1; i < m;) {
26+
while (j >= 0 && P[i] != P[j]) j = b[j];
27+
b[++i] = ++j;
28+
}
29+
}
30+
trans get(char c) {
31+
trans ans(m);
32+
for(int i = 0, j, cnt; i < m; i++) {
33+
j = i; cnt = 0;
34+
while(j >= 0 && c != P[j]) j = b[j];
35+
j++;
36+
if (j == m) cnt++, j = b[j];
37+
ans.to[i] = j;
38+
ans.match[i] = cnt;
39+
}
40+
return ans;
41+
}
42+
};

contents.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ number_theory/pollard.cpp Pollard Rho
1010
number_theory/totient.cpp $\phi$ of Euler
1111
number_theory/prime_factors.cpp Compute prime factors
1212
number_theory/finite_field.cpp Finite Field operations
13-
number_theory/modular_sqrt.cpp Modular squareroot (Tonelli-Shanks)
13+
number_theory/modular_sqrt.cpp Modular squareroot (Tonelli-Shanks)
1414

1515
[Numeric]
1616
numeric/binomial.cpp Binomial
@@ -22,7 +22,7 @@ numeric/gauss.cpp Gaussian elimination
2222
numeric/karatsuba.cpp Karatsuba
2323
numeric/incexc.cpp Inclusion-Exclusion principle
2424
numeric/lagrangepoly.cpp Lagrange polynomial interpolation
25-
numeric/floorsum.cpp Floor-sum
25+
numeric/floorsum.cpp Floor-sum
2626

2727
[Graph algorithms]
2828
graphs/dijkstra.cpp Dijkstra Shortest path
@@ -57,9 +57,9 @@ graphs/chromatic.cpp Chromatic Number
5757
graphs/dynamic_reachdag.cpp Dynamic reachability in DAG
5858
graphs/kshortest.cpp K-ShortestPaths
5959
graphs/func_lenha.cpp Functional graphs
60-
graphs/mstdir.cpp Minimum arborescence (MST digraph)
61-
graphs/steinertree.cpp Minimum Steiner tree
62-
graphs/erdos.cpp Erdos Gallai theorem
60+
graphs/mstdir.cpp Minimum arborescence (MST digraph)
61+
graphs/steinertree.cpp Minimum Steiner tree
62+
graphs/erdos.cpp Erdos Gallai theorem
6363

6464
[Data structures]
6565
data_structures/sparseTable.cpp Sparse Table
@@ -132,9 +132,9 @@ geometry/Angle.cpp Angle sorting
132132
geometry/kdTree.cpp K-D Tree
133133
geometry/point3d.cpp Point3D
134134
geometry/3dhull.cpp Convex hull 3D
135-
geometry/halfplaneIS.cpp Half Plane Intersection
136-
geometry/rayDistance.cpp Ray(semi-reta) distance
137-
# geometry/GeometryRusso.cpp Another Geometry lib
135+
geometry/halfplaneIS.cpp Half Plane Intersection
136+
geometry/rayDistance.cpp Ray(semi-reta) distance
137+
# geometry/GeometryRusso.cpp Another Geometry lib
138138

139139
[Java]
140140
Java/template.java Template

notebook.pdf

21.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)