You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This repo hosts KACTL, KTH's ICPC team reference document.
4
-
It consists of 25 pages of copy-paste:able code, for use in ICPC-style programming competitions.
3
+
This repo hosts KACTL, [KTH](https://en.wikipedia.org/wiki/KTH_Royal_Institute_of_Technology)'s ICPC team reference document.
4
+
It consists of 25 pages of copy-pasteable C++ code, for use in ICPC-style programming competitions.
5
5
6
6
See [kactl.pdf](https://github.com/kth-competitive-programming/kactl/blob/master/kactl.pdf) for the final, browsable version,
7
7
and [content/](https://github.com/kth-competitive-programming/kactl/tree/master/content) for raw source code.
8
8
9
9
## Aspirations
10
10
11
-
KACTL algorithms should be: useful, short, fast enough, readable, and if relevant, easy to modify.
12
-
Short and readable sometimes conflict -- usually then short takes precedence, although
13
-
the algorithms should still be made easy to type in and hard to make typos in (since ICPC-style contests
14
-
require you to copy them from paper).
15
-
11
+
KACTL algorithms should be: useful, short, fast enough, well tested, and if relevant, readable and easy to modify.
16
12
They should *not* be overly generic, since code is manually typed and that just adds overhead.
17
13
Due to space issues, we also exclude algorithms that are very common/simple (e.g., Dijkstra), or very uncommon (general weighted matching).
18
14
19
-
If you feel that something is missing, could be cleaned up, or notice a bug, please file an issue or send us a pull request!
15
+
If you feel that something is missing, could be cleaned up, or notice a bug, please file an issue or [send a pull request](https://help.github.com/articles/fork-a-repo/)!
20
16
21
-
## Hacking on KACTL
17
+
## Customizing KACTL
22
18
23
-
For coding style, try to copy existing code.
24
-
Each algorithm should contain a header with the author of the code, the date it
25
-
was added, a description of the algorithm, its testing status, and preferably also
26
-
source, license and time complexity.
27
-
Line width is 63 chars, with tabs for indentation (tab = 2 spaces in the pdf).
19
+
While KACTL is usable as is, it's also easy to modify if you want to create a personalized copy.
20
+
In particular, you may want to change the cover page, or make your own choice of algorithms to include --
21
+
due to space concerns, not all algorithms in the repo are included in the pdf.
22
+
You may also want to enable colored syntax highlighting.
28
23
29
-
When adding/removing files, edit the corresponding `chapter.tex` file as well.
30
-
`chapter.tex` also contains all non-source code, e.g. math and textual descriptions.
31
-
For nicer alignment you might want to use `\hardcolumnbreak`, `\columnbreak` or `\newpage` commands,
24
+
`content/kactl.tex` is the main file of KACTL, and can be edited to change team name, logo, syntax highlighting, etc.
25
+
It imports `chapter.tex` files from each of the `content/` subdirectories, which define the contents of each chapter.
26
+
These include source code, text and math in the form of LaTeX.
27
+
To add/remove code from a chapter, add/remove a corresponding `\kactlimport` line from the `chapter.tex` file.
28
+
For nicer alignment you might want to insert `\hardcolumnbreak`, `\columnbreak` or `\newpage` commands,
32
29
though this is usually only done before important contests, and not on master.
30
+
The algorithms that are not included in the pdf are left commented out in `chapter.tex`.
33
31
34
-
To build KACTL, type `make kactl` (or `make fast`) on a \*NIX machine -- this will update `kactl.pdf`.
32
+
To build KACTL, type `make kactl` (or `make fast`) on a \*nix machine -- this will update `kactl.pdf`.
35
33
(Windows might work as well, but is not tested.) `doc/README` has a few more notes about this.
36
34
37
-
kactl.pdf is to be kept to 25 pages + cover page.
38
-
Occasionally the generated kactl.pdf is committed to the repo for convenience, but not too often because it makes git operations slower.
35
+
Tips:
36
+
1. Check out what's excluded by default by running `make showexcluded`.
37
+
The default configuration is chosen to be a reasonable balance for beginners
38
+
and advanced teams.
39
+
2. Take advantage of the hashing when typing in these algorithms. Each
40
+
algorithm has a 6 character MD5 hash in the upper right. This hash can be
41
+
generated by using `hash.sh` or the `:Hash` command from the `.vimrc`. The
42
+
hashing ignores whitespace and comments.
39
43
40
-
Before printing KACTL for an official contest, you may want to locally change the arguments to `\team`, `\contest`, etc. in build/kactl.tex to something more fitting,
41
-
You may also enable colored syntax highlighting in the same file.
44
+
## Coding style
42
45
43
-
To upstream your changes, [send a pull request](https://help.github.com/articles/fork-a-repo/).
46
+
KACTL uses a relatively terse coding style, with a handful of macros/typedefs defined in the
47
+
[template](https://github.com/kth-competitive-programming/kactl/blob/master/content/contest/template.cpp) that help shorten the code.
48
+
Line width is 63 chars, with tabs for indentation (tab = 2 spaces in the pdf).
49
+
50
+
Each algorithm contains a header with the author of the code, the date it
51
+
was added, a description of the algorithm, its testing status, and preferably also
52
+
source, license and time complexity.
53
+
54
+
kactl.pdf is to be kept to 25 pages + cover page.
55
+
Occasionally the generated kactl.pdf is committed to the repo for convenience, but not too often because it makes git operations slower.
44
56
45
57
## Testing
46
58
47
-
KACTL algorithms are tested manually, on online judges and/or using fuzz-tests (see the `fuzz-tests` directory).
48
-
Simple variable renamings etc. don't need testing, but it's prudent to at least run `./test-compiles.sh file.h` to make sure the file still compiles.
59
+
KACTL aims for a high level of confidence in algorithm correctness.
60
+
Testing is done both on online judges and (for newer algorithms) with stress tests
61
+
that compare output to a more naive algorithm for a large amount of randomly generated cases.
62
+
These tests live in the `stress-tests` directory, and are run with CI on every commit. The CI also verifies that all headers compile (except for a whitelist in `docs/scripts/skip_headers`) and that the latex compiles.
49
63
50
64
`old-unit-tests` contains a couple of broken unit tests, last touched about ten years ago.
51
65
@@ -57,4 +71,4 @@ Many source files are marked with license (we try to go with
57
71
Presumably good will is to be assumed from other authors, though, and in many cases permission should not be needed since the code is not distributed.
58
72
To help trace things back, sources and authors are noted in source files.
59
73
60
-
Everything in `fuzz-tests`and `build`is implicitly CC0.
74
+
Everything in `stress-tests` is implicitly CC0, except reference implementations taken from around the Internet.
Copy file name to clipboardExpand all lines: content/combinatorial/chapter.tex
+23-1Lines changed: 23 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -34,11 +34,28 @@ \section{Partitions and subsets}
34
34
\end{tabular}
35
35
\end{center}
36
36
37
+
\subsection{Lucas' Theorem}
38
+
Let $n,m$ be non-negative integers and $p$ a prime. Write $n=n_kp^k+...+n_1p+n_0$ and $m=m_kp^k+...+m_1p+m_0$. Then $\binom{n}{m} \equiv\prod_{i=0}^k\binom{n_i}{m_i} \pmod{p}$.
39
+
37
40
\subsection{Binomials}
38
-
\kactlimport{binomialModPrime.h}
39
41
\kactlimport{multinomial.h}
40
42
41
43
\section{General purpose numbers}
44
+
\subsection{Bernoulli numbers}
45
+
EGF of Bernoulli numbers is $B(t)=\frac{t}{e^t-1}$ (FFT-able).
0 commit comments