Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbdee148

Browse files
committed
2 parentsbee2358 +4bb7a0d commitbdee148

File tree

40 files changed

+345
-95
lines changed

40 files changed

+345
-95
lines changed

‎.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
-name:Set up Python
2020
uses:actions/setup-python@v5.2.0
2121
with:
22-
python-version:'3.8'
22+
python-version:'3.11'
2323
-name:Install mkdocs-material
2424
run:|
2525
scripts/install-mkdocs.sh

‎mkdocs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ theme:
2222
icon:
2323
repo:fontawesome/brands/github
2424
features:
25-
-navigation.tabs
2625
-toc.integrate
2726
-search.suggest
2827
-content.code.copy
@@ -57,12 +56,13 @@ markdown_extensions:
5756
permalink:true
5857

5958
plugins:
59+
-toggle-sidebar:
60+
toggle_button:all
6061
-mkdocs-simple-hooks:
6162
hooks:
6263
on_env:"hooks:on_env"
6364
-search
64-
-tags:
65-
tags_file:tags.md
65+
-tags
6666
-literate-nav:
6767
nav_file:navigation.md
6868
-git-revision-date-localized:

‎scripts/install-mkdocs.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
pip install \
44
"mkdocs-material>=9.0.2" \
5+
mkdocs-toggle-sidebar-plugin \
56
mkdocs-macros-plugin \
67
mkdocs-literate-nav \
78
mkdocs-git-authors-plugin \

‎src/algebra/factorization.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ If $p$ is smaller than $\sqrt{n}$, the repetition will likely start in $O(\sqrt[
246246
Here is a visualization of such a sequence $\{x_i \bmod p\}$ with $n = 2206637$, $p = 317$, $x_0 = 2$ and $f(x) = x^2 + 1$.
247247
From the form of the sequence you can see very clearly why the algorithm is called Pollard's $\rho$ algorithm.
248248

249-
<center>![Pollard's rho visualization](pollard_rho.png)</center>
249+
<divstyle="text-align:center;">
250+
<imgsrc="pollard_rho.png"alt="Pollard's rho visualization">
251+
</div>
250252

251253
Yet, there is still an open question.
252254
How can we exploit the properties of the sequence $\{x_i \bmod p\}$ to our advantage without even knowing the number $p$ itself?

‎src/algebra/fibonacci-numbers.md

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Fibonacci numbers possess a lot of interesting properties. Here are a few of the
2222

2323
$$F_{n-1} F_{n+1} - F_n^2 = (-1)^n$$
2424

25+
>This can be proved by induction. A one-line proof by Knuth comes from taking the determinant of the 2x2 matrix form below.
26+
2527
* The "addition" rule:
2628

2729
$$F_{n+k} = F_k F_{n+1} + F_{k-1} F_n$$
@@ -116,11 +118,63 @@ In this way, we obtain a linear solution, $O(n)$ time, saving all the values pri
116118
117119
### Matrix form
118120
119-
It is easytoprovethefollowing relation:
121+
To go from $(F_n, F_{n-1})$to$(F_{n+1}, F_n)$, we can expressthelinear recurrence as a 2x2 matrix multiplication:
120122
121-
$$\begin{pmatrix} 1 & 1 \cr 1 & 0 \cr\end{pmatrix} ^ n = \begin{pmatrix} F_{n+1} & F_{n} \cr F_{n} & F_{n-1} \cr\end{pmatrix}$$
123+
$$
124+
\begin{pmatrix}
125+
1 & 1 \\
126+
1 & 0
127+
\end{pmatrix}
128+
\begin{pmatrix}
129+
F_n \\
130+
F_{n-1}
131+
\end{pmatrix}
132+
=
133+
\begin{pmatrix}
134+
F_n + F_{n-1} \\
135+
F_{n}
136+
\end{pmatrix}
137+
=
138+
\begin{pmatrix}
139+
F_{n+1} \\
140+
F_{n}
141+
\end{pmatrix}
142+
$$
143+
144+
This lets us treat iterating the recurrence as repeated matrix multiplication, which has nice properties. In particular,
145+
146+
$$
147+
\begin{pmatrix}
148+
1 & 1 \\
149+
1 & 0
150+
\end{pmatrix}^n
151+
\begin{pmatrix}
152+
F_1 \\
153+
F_0
154+
\end{pmatrix}
155+
=
156+
\begin{pmatrix}
157+
F_{n+1} \\
158+
F_{n}
159+
\end{pmatrix}
160+
$$
161+
162+
where $F_1 = 1, F_0 = 0$.
163+
In fact, since
164+
165+
$$
166+
\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}
167+
= \begin{pmatrix} F_2 & F_1 \\ F_1 & F_0 \end{pmatrix}
168+
$$
169+
170+
we can use the matrix directly:
171+
172+
$$
173+
\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}^n
174+
= \begin{pmatrix} F_{n+1} & F_n \\ F_n & F_{n-1} \end{pmatrix}
175+
$$
122176
123-
Thus, in order to find $F_n$ in $O(log n)$ time, we must raise the matrix to n. (See [Binary exponentiation](binary-exp.md))
177+
Thus, in order to find $F_n$ in $O(\log n)$ time, we must raise the matrix to n. (See [Binary exponentiation](binary-exp.md))
124178
125179
```{.cpp file=fibonacci_matrix}
126180
struct matrix {

‎src/algebra/sieve-of-eratosthenes.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ And we continue this procedure until we have processed all numbers in the row.
1919

2020
In the following image you can see a visualization of the algorithm for computing all prime numbers in the range $[1; 16]$. It can be seen, that quite often we mark numbers as composite multiple times.
2121

22-
<center>![Sieve of Eratosthenes](sieve_eratosthenes.png)</center>
22+
<divstyle="text-align:center;">
23+
<imgsrc="sieve_eratosthenes.png"alt="Sieve of Eratosthenes">
24+
</div>
2325

2426
The idea behind is this:
2527
A number is prime, if none of the smaller prime numbers divides it.

‎src/combinatorics/burnside.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,8 @@ int solve(int n, int m) {
266266
return sum / s.size();
267267
}
268268
```
269+
## Practice Problems
270+
* [CSES - Counting Necklaces](https://cses.fi/problemset/task/2209)
271+
* [CSES - Counting Grids](https://cses.fi/problemset/task/2210)
272+
* [Codeforces - Buildings](https://codeforces.com/gym/101873/problem/B)
273+
* [CS Academy - Cube Coloring](https://csacademy.com/contest/beta-round-8/task/cube-coloring/)

‎src/data_structures/fenwick.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ where $|$ is the bitwise OR operator.
128128
The following image shows a possible interpretation of the Fenwick treeas tree.
129129
The nodes of the tree show the ranges they cover.
130130

131-
<center>![Binary Indexed Tree](binary_indexed_tree.png)</center>
131+
<divstyle="text-align: center;">
132+
<imgsrc="binary_indexed_tree.png"alt="Binary Indexed Tree">
133+
</div>
132134

133135
## Implementation
134136

‎src/dynamic_programming/divide-and-conquer-dp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ both!
113113
- [SPOJ - LARMY](https://www.spoj.com/problems/LARMY/)
114114
- [SPOJ - NKLEAVES](https://www.spoj.com/problems/NKLEAVES/)
115115
- [Timus - Bicolored Horses](https://acm.timus.ru/problem.aspx?space=1&num=1167)
116-
- [USACO - Circular Barn](http://www.usaco.org/index.php?page=viewproblem2&cpid=616)
116+
- [USACO - Circular Barn](https://usaco.org/index.php?page=viewproblem2&cpid=626)
117117
- [UVA - Arranging Heaps](https://onlinejudge.org/external/125/12524.pdf)
118118
- [UVA - Naming Babies](https://onlinejudge.org/external/125/12594.pdf)
119119

‎src/dynamic_programming/knuth-optimization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ $$
7777
\sum\limits_{i=1}^N \sum\limits_{j=i}^{N-1} [opt(i+1,j+1)-opt(i,j)].
7878
$$
7979

80-
As you see, most of the terms in this expression cancel each other out, except for positive terms with $j=N$ and negative terms with $i=1$. Thus, the whole sum can be estimated as
80+
As you see, most of the terms in this expression cancel each other out, except for positive terms with $j=N-1$ and negative terms with $i=1$. Thus, the whole sum can be estimated as
8181

8282
$$
8383
\sum\limits_{k=1}^N[opt(k,N)-opt(1,k)] = O(n^2),

‎src/geometry/basic-geometry.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ The dot (or scalar) product $\mathbf a \cdot \mathbf b$ for vectors $\mathbf a$
112112
Geometrically it is product of the length of the first vector by the length of the projection of the second vector onto the first one.
113113
As you may see from the image below this projection is nothing but $|\mathbf a| \cos \theta$ where $\theta$ is the angle between $\mathbf a$ and $\mathbf b$. Thus $\mathbf a\cdot \mathbf b = |\mathbf a| \cos \theta \cdot |\mathbf b|$.
114114

115-
<center>![](https://upload.wikimedia.org/wikipedia/commons/thumb/3/3e/Dot_Product.svg/300px-Dot_Product.svg.png)</center>
115+
<div style="text-align: center;">
116+
<imgsrc="https://upload.wikimedia.org/wikipedia/commons/thumb/3/3e/Dot_Product.svg/300px-Dot_Product.svg.png"alt="">
117+
</div>
116118

117119
The dot product holds some notable properties:
118120

@@ -181,7 +183,9 @@ To see the next important property we should take a look at the set of points $\
181183
You can see that this set of points is exactly the set of points for which the projection onto $\mathbf a$ is the point $C \cdot \dfrac{\mathbf a}{|\mathbf a|}$ and they form a hyperplane orthogonal to $\mathbf a$.
182184
You can see the vector $\mathbf a$ alongside with several such vectors having same dot product with it in 2D on the picture below:
183185

184-
<center>![Vectors having same dot product with a](https://i.imgur.com/eyO7St4.png)</center>
186+
<divstyle="text-align:center;">
187+
<imgsrc="https://i.imgur.com/eyO7St4.png"alt="Vectors having same dot product with a">
188+
</div>
185189

186190
In 2D these vectors will form a line, in 3D they will form a plane.
187191
Note that this result allows us to define a line in 2D as $\mathbf r\cdot \mathbf n=C$ or $(\mathbf r - \mathbf r_0)\cdot \mathbf n=0$ where $\mathbf n$ is vector orthogonal to the line and $\mathbf r_0$ is any vector already present on the line and $C = \mathbf r_0\cdot \mathbf n$.
@@ -192,14 +196,18 @@ In the same manner a plane can be defined in 3D.
192196
###Definition
193197

194198
Assume you have three vectors $\mathbf a$, $\mathbf b$ and $\mathbf c$ in 3D space joined in a parallelepiped as in the picture below:
195-
<center>![Three vectors](https://upload.wikimedia.org/wikipedia/commons/thumb/3/3e/Parallelepiped_volume.svg/240px-Parallelepiped_volume.svg.png)</center>
199+
<divstyle="text-align:center;">
200+
<imgsrc="https://upload.wikimedia.org/wikipedia/commons/thumb/3/3e/Parallelepiped_volume.svg/240px-Parallelepiped_volume.svg.png"alt="Three vectors">
201+
</div>
196202

197203
How would you calculate its volume?
198204
From school we know that we should multiply the area of the base with the height, which is projection of $\mathbf a$ onto direction orthogonal to base.
199205
That means that if we define $\mathbf b \times \mathbf c$ as the vector which is orthogonal to both $\mathbf b$ and $\mathbf c$ and which length is equal to the area of the parallelogram formed by $\mathbf b$ and $\mathbf c$ then $|\mathbf a\cdot (\mathbf b\times\mathbf c)|$ will be equal to the volume of the parallelepiped.
200206
For integrity we will say that $\mathbf b\times \mathbf c$ will be always directed in such way that the rotation from the vector $\mathbf b$ to the vector $\mathbf c$ from the point of $\mathbf b\times \mathbf c$ is always counter-clockwise (see the picture below).
201207

202-
<center>![cross product](https://upload.wikimedia.org/wikipedia/commons/thumb/b/b0/Cross_product_vector.svg/250px-Cross_product_vector.svg.png)</center>
208+
<divstyle="text-align:center;">
209+
<imgsrc="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b0/Cross_product_vector.svg/250px-Cross_product_vector.svg.png"alt="cross product">
210+
</div>
203211

204212
This defines the cross (or vector) product $\mathbf b\times \mathbf c$ of the vectors $\mathbf b$ and $\mathbf c$ and the triple product $\mathbf a\cdot(\mathbf b\times \mathbf c)$ of the vectors $\mathbf a$, $\mathbf b$ and $\mathbf c$.
205213

‎src/geometry/convex_hull_trick.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ The idea of this approach is to maintain a lower convex hull of linear functions
1717
Actually it would be a bit more convenient to consider them not as linear functions, but as points $(k;b)$ on the plane such that we will have to find the point which has the least dot product with a given point $(x;1)$, that is, for this point $kx+b$ is minimized which is the same as initial problem.
1818
Such minimum will necessarily be on lower convex envelope of these points as can be seen below:
1919

20-
<center> ![lower convex hull](convex_hull_trick.png) </center>
20+
<divstyle="text-align:center;">
21+
<imgsrc="convex_hull_trick.png"alt="lower convex hull">
22+
</div>
2123

2224
One has to keep points on the convex hull and normal vectors of the hull's edges.
2325
When you have a $(x;1)$ query you'll have to find the normal vector closest to it in terms of angles between them, then the optimum linear function will correspond to one of its endpoints.
@@ -90,7 +92,9 @@ Assume we're in some vertex corresponding to half-segment $[l,r)$ and the functi
9092
9193
Here is the illustration of what is going on in the vertex when we add new function:
9294
93-
<center>![Li Chao Tree vertex](li_chao_vertex.png)</center>
95+
<div style="text-align: center;">
96+
<img src="li_chao_vertex.png" alt="Li Chao Tree vertex">
97+
</div>
9498
9599
Let's go to implementation now. Once again we will use complex numbers to keep linear functions.
96100

‎src/geometry/delaunay.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ Because of the duality, we only need a fast algorithm to compute only one of $V$
3030
##Quad-edge data structure
3131

3232
During the algorithm $D$ will be stored inside the quad-edge data structure. This structure is described in the picture:
33-
<center>![Quad-Edge](quad-edge.png)</center>
33+
<divstyle="text-align:center;">
34+
<imgsrc="quad-edge.png"alt="Quad-Edge">
35+
</div>
3436

3537
In the algorithm we will use the following functions on edges:
3638

‎src/geometry/intersecting_segments.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,24 @@ The naive solution algorithm is to iterate over all pairs of segments in $O(n^2)
1616
Let's draw a vertical line $x = -\infty$ mentally and start moving this line to the right.
1717
In the course of its movement, this line will meet with segments, and at each time a segment intersect with our line it intersects in exactly one point (we will assume that there are no vertical segments).
1818

19-
<center>![sweep line and line segment intersection](sweep_line_1.png)</center>
19+
<divstyle="text-align:center;">
20+
<imgsrc="sweep_line_1.png"alt="sweep line and line segment intersection">
21+
</div>
2022

2123
Thus, for each segment, at some point in time, its point will appear on the sweep line, then with the movement of the line, this point will move, and finally, at some point, the segment will disappear from the line.
2224

2325
We are interested in the**relative order of the segments** along the vertical.
2426
Namely, we will store a list of segments crossing the sweep line at a given time, where the segments will be sorted by their $y$-coordinate on the sweep line.
2527

26-
<center>![relative order of the segments across sweep line](sweep_line_2.png)</center>
28+
<divstyle="text-align:center;">
29+
<imgsrc="sweep_line_2.png"alt="relative order of the segments across sweep line">
30+
</div>
2731

2832
This order is interesting because intersecting segments will have the same $y$-coordinate at least at one time:
2933

30-
<center>![intersection point having same y-coordinate](sweep_line_3.png)</center>
34+
<divstyle="text-align:center;">
35+
<imgsrc="sweep_line_3.png"alt="intersection point having same y-coordinate">
36+
</div>
3137

3238
We formulate key statements:
3339

‎src/geometry/lattice-points.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ We have two cases:
3838
This amount is the same as the number of points such that $0 < y \leq (k - \lfloor k \rfloor) \cdot x + (b - \lfloor b \rfloor)$.
3939
So we reduced our problem to $k'= k - \lfloor k \rfloor$, $b' = b - \lfloor b \rfloor$ and both $k'$ and $b'$ less than $1$ now.
4040
Here is a picture, we just summed up blue points and subtracted the blue linear function from the black one to reduce problem to smaller values for $k$ and $b$:
41-
<center>![Subtracting floored linear function](lattice.png)</center>
41+
<divstyle="text-align:center;">
42+
<imgsrc="lattice.png"alt="Subtracting floored linear function">
43+
</div>
4244

4345
- $k < 1$ and $b < 1$.
4446

@@ -51,7 +53,9 @@ We have two cases:
5153

5254
which returns us back to the case $k>1$.
5355
You can see new reference point $O'$ and axes $X'$ and $Y'$ in the picture below:
54-
<center>![New reference and axes](mirror.png)</center>
56+
<divstyle="text-align:center;">
57+
<imgsrc="mirror.png"alt="New reference and axes">
58+
</div>
5559
As you see, in new reference system linear function will have coefficient $\tfrac 1 k$ and its zero will be in the point $\lfloor k\cdot n + b \rfloor-(k\cdot n+b)$ which makes formula above correct.
5660

5761
##Complexity analysis

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp