Advertisement
penguin71630

CodeBook

Sep 25th, 2021
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 7.37 KB | None | 0 0
  1. \documentclass[twocolumn]{article}
  2.  
  3. \usepackage[top=2cm,bottom=2cm,left=2cm,right=2cm]{geometry}
  4. \usepackage[utf8]{inputenc}
  5. \usepackage{xeCJK}
  6. \usepackage{fontspec}
  7. \usepackage{listings}
  8. \usepackage{fancyhdr}
  9. \usepackage{changepage}
  10. \usepackage{color}
  11. \usepackage{amsmath}
  12. \usepackage{amssymb}
  13. \usepackage{amsthm}
  14.  
  15. \setCJKmainfont{NotoSerifTC-Medium.otf}
  16. \XeTeXlinebreaklocale "zh"
  17. \XeTeXlinebreakskip = 0pt plus 1pt
  18.  
  19. \lstset{
  20. language=C++,
  21. basicstyle=\ttfamily,
  22. numberstyle=\footnotesize,
  23. stepnumber=1,
  24. numbersep=5pt,
  25. backgroundcolor=\color{white},
  26. showspaces=false,
  27. showstringspaces=false,
  28. showtabs=false,
  29. frame=false,
  30. tabsize=2,
  31. captionpos=b,
  32. breaklines=true,
  33. breakatwhitespace=false,
  34. escapeinside={\%*}{*)},
  35. morekeywords={*},
  36. literate={\ \ }{{\ }}1
  37. }
  38.  
  39. \begin{document}
  40.  
  41. \setlength\parindent{0pt}
  42.  
  43. \tableofcontents
  44.  
  45. \pagestyle{fancy}
  46. \fancyfoot{}
  47. \fancyhead[L]{Gino}
  48. \fancyhead[C]{Codebook}
  49. \fancyhead[R]{\thepage}
  50.  
  51. \newpage
  52.  
  53. \section{Reminder}
  54.  
  55. \subsection{Bug List}
  56. \lstinputlisting{note/BugList.txt}
  57.  
  58. \subsection{常見手法}
  59. \lstinputlisting{note/UsefulTrick.txt}
  60.  
  61. \subsection{策略}
  62.  
  63. \subsubsection{賽前守則}
  64. \lstinputlisting{note/LawBeforeContest.txt}
  65.  
  66. \subsubsection{賽中策略}
  67. \lstinputlisting{note/Strategy.txt}
  68.  
  69. \subsubsection{賽中心態調整}
  70. \lstinputlisting{note/CoolDown.txt}
  71.  
  72. \section{Basic}
  73.  
  74. \subsection{Default Code}
  75. \lstinputlisting{code/Default.cpp}
  76.  
  77. \subsection{PBDS}
  78. \lstinputlisting{code/PBDS.cpp}
  79.  
  80. \subsection{Random}
  81. \lstinputlisting{code/Random.cpp}
  82.  
  83. \section{Data Structure}
  84.  
  85. \subsection{BIT}
  86. \lstinputlisting{code/BIT.cpp}
  87.  
  88. \subsection{Segment Tree - Instruction}
  89. \lstinputlisting{code/SegmentTree-Instruction.cpp}
  90.  
  91. \subsection{Segment Tree}
  92. \lstinputlisting{code/SegmentTree.cpp}
  93.  
  94. \subsection{Sparse Table}
  95. \lstinputlisting{code/SparseTable.cpp}
  96.  
  97. \section{Graph}
  98.  
  99. \subsection{Dijkstra}
  100. \lstinputlisting{code/Dijkstra.cpp}
  101.  
  102. \subsection{Floyd-Warshall}
  103. \lstinputlisting{code/FloydWarshall.cpp}
  104.  
  105. \subsection{SPFA}
  106. \lstinputlisting{code/SPFA.cpp}
  107.  
  108. \subsection{Bellman-Ford}
  109. \lstinputlisting{code/BellmanFord.cpp}
  110.  
  111. \subsection{MST - Kruskal}
  112. \lstinputlisting{code/MST-kruskal.cpp}
  113.  
  114. \subsection{MST - prim}
  115. \lstinputlisting{code/MST-prim.cpp}
  116.  
  117. \subsection{SCC - Tarjan}
  118. \lstinputlisting{code/SCC-Tarjan.cpp}
  119.  
  120. \subsection{Eulerian Path - Undir}
  121. \lstinputlisting{code/EulerianPath-Undir.cpp}
  122.  
  123. \subsection{Eulerian Path - Dir}
  124. \lstinputlisting{code/EulerianPath-Dir.cpp}
  125.  
  126. \subsection{Hamilton Path}
  127. \lstinputlisting{code/HamiltonPath.cpp}
  128.  
  129. \section{Tree}
  130.  
  131. \subsection{LCA}
  132. \lstinputlisting{code/LCA.cpp}
  133.  
  134. \section{String}
  135.  
  136. \subsection{Rolling Hash}
  137. \lstinputlisting{code/RollingHash.cpp}
  138.  
  139. \section{Geometry}
  140.  
  141. \subsection{Basic Operations}
  142. \lstinputlisting{code/BasicOperator.cpp}
  143.  
  144. \subsection{Sort by Angle}
  145. \lstinputlisting{code/SortByAngle.cpp}
  146.  
  147. \subsection{Line Intersection}
  148. \lstinputlisting{code/LineIntersect.cpp}
  149.  
  150. \subsection{In-polygon Test}
  151. \lstinputlisting{code/InPolygon.cpp}
  152.  
  153. \subsection{Polygon Area}
  154. \lstinputlisting{code/PolygonArea.cpp}
  155.  
  156. \subsection{Convex Hull}
  157. \lstinputlisting{code/ConvexHull.cpp}
  158.  
  159. \subsection{Closest Pair of Point}
  160. \lstinputlisting{code/ClosestPointPair.cpp}
  161.  
  162. \subsection{Pick's Theorem}
  163.  
  164. Consider a polygon which vertices are all lattice points.
  165.  
  166. Let $i$ = number of points inside the polygon.
  167.  
  168. Let $b$ = number of points on the boundary of the polygon.
  169.  
  170. Then we have the following formula:
  171.  
  172. $$
  173. Area = i + \frac{b}{2} - 1
  174. $$
  175. \section{Number Theory}
  176. \subsection{Fast Power}
  177. Note: $a^n \equiv a^{(n \ mod \ p-1)} (mod \ p)$
  178. \lstinputlisting{code/FastPow.cpp}
  179. \subsection{Matrix Fast Power}
  180. \lstinputlisting{code/MatrixFastPow.cpp}
  181. \subsection{Extend GCD}
  182. \lstinputlisting{code/ExtGCD.cpp}
  183. \subsection{Prime Seive + Defactor}
  184. \lstinputlisting{code/PrimeSeive+Defactor.cpp}
  185. \subsection{Other Formulas}
  186. \begin{itemize}
  187.    \item Inversion:\\ $aa^{-1} \equiv 1 \pmod{m}$. $a^{-1}$ exists iff $\gcd(a,m)=1$.
  188.    
  189.    \item Linear inversion:\\ $a^{-1} \equiv (m - \lfloor\frac{m}{a}\rfloor) \times (m \bmod a)^{-1} \pmod{m}$
  190.    
  191.    \item Fermat's little theorem:\\ $a^p \equiv a \pmod{p}$ if $p$ is prime.
  192.    
  193.    \item Euler function:\\ $\phi(n)=n \prod_{p|n} \frac{p-1}{p}$
  194.    
  195.    \item Euler theorem:\\ $a^{\phi(n)} \equiv 1 \pmod{n}$ if $\gcd(a,n) = 1$.
  196.    
  197.    \item Extended Euclidean algorithm:\\
  198.    $ax+by=\gcd(a,b)=\gcd(b, a \bmod b)=\gcd(b, a-\lfloor\frac{a}{b}\rfloor b)=bx_1+(a-\lfloor\frac{a}{b}\rfloor b)y_1=ay_1+b(x_1-\lfloor\frac{a}{b}\rfloor y_1)$
  199.    
  200.    \item Divisor function:\\ $\sigma_x(n) = \sum_{d|n}d^x$. $n=\prod_{i=1}^r p_i^{a_i}$.\\ $\sigma_x(n)=\prod_{i=1}^r \frac{p_i^{(a_i+1)x}-1}{p_i^x-1}$ if $x \neq 0$. $\sigma_0(n)=\prod_{i=1}^r (a_i+1)$.
  201.    
  202.    \item Chinese remainder theorem:\\ $x \equiv a_i \pmod{m_i}$.\\
  203.        $M=\prod m_i$. $M_i=M/m_i$. $t_i=M_i^{-1}$.\\
  204.        $x = kM + \sum a_i t_i M_i$, $k \in \mathbb{Z}$.
  205. \end{itemize}
  206. \section{Combinatorics}
  207. \subsection{Basic Formulas}
  208. \begin{itemize}
  209.    \item $P^n_k=\frac{n!}{(n-k)!}$
  210.    \item $C^n_k=\frac{n!}{(n-k)!k!}$
  211.    \item $H^n_k=C^{n+k-1}_k=\frac{(n+k-1)!}{k!(n-1)!}$
  212. \end{itemize}
  213. \subsection{Catalan Number}
  214. $$
  215. C_0=1, C_n=\sum_{i=0}^{n-1} C_i C_{n-1-i}
  216. $$
  217. $$
  218. C_n=C_n^{2n}-C_{n-1}^{2n}
  219. $$
  220. \begin{center}
  221.    \begin{tabular}{r|lllll}
  222.        0 & 1 & 1 & 2 & 5 \\
  223.        4 & 14 & 42 & 132 & 429 \\
  224.        8 & 1430 & 4862 & 16796 & 58786 \\
  225.        12 & 208012 & 742900 & 2674440 & 9694845
  226.    \end{tabular}
  227. \end{center}
  228. \subsection{Burnside's Lemma}
  229. Let $X$ be the original set.
  230. Let $G$ be the group of operations acting on $X$.
  231. Let $X^g$ be the set of $x$ not affected by $g$.
  232. Let $X/G$ be the set of orbits.
  233. Then the following equation holds:
  234. $$
  235. |X/G| = \frac{1}{|G|} \sum_{g \in G} |X^g|
  236. $$
  237. \section{Special Numbers}
  238. \subsection{Fibonacci Series}
  239. $$f(n)=f(n-1)+f(n-2)$$
  240. \begin{equation*}
  241.    \begin{bmatrix}
  242.        f(n) \\
  243.        f(n - 1)
  244.    \end{bmatrix}
  245.    =
  246.    \begin{bmatrix}
  247.        1 & 1 \\
  248.        1 & 0
  249.    \end{bmatrix}
  250.    \begin{bmatrix}
  251.        1 \\
  252.        0
  253.    \end{bmatrix}
  254. \end{equation*}
  255. \begin{center}
  256.    \begin{tabular}{r|lllll}
  257.        1 & 1 & 1 & 2 & 3 \\
  258.        5 & 5 & 8 & 13 & 21 \\
  259.        9 & 34 & 55 & 89 & 144 \\
  260.        13 & 233 & 377 & 610 & 987 \\
  261.        17 & 1597 & 2584 & 4181 & 6765 \\
  262.        21 & 10946 & 17711 & 28657 & 46368 \\
  263.        25 & 75025 & 121393 & 196418 & 317811 \\
  264.        29 & 514229 & 832040 & 1346269 & 2178309 \\
  265.        33 & 3524578 & 5702887 & 9227465 & 14930352
  266.    \end{tabular}
  267. \end{center}
  268. $f(45) \approx 10^9$\\
  269. $f(88) \approx 10^{18}$
  270.  
  271.  
  272. \subsection{Prime Numbers}
  273.  
  274. First 50 prime numbers:\\
  275. \begin{center}
  276.    \begin{tabular}{r|llllllllll}
  277.        1 & 2 & 3 & 5 & 7 & 11 \\
  278.        6 & 13 & 17 & 19 & 23 & 29 \\
  279.        11 & 31 & 37 & 41 & 43 & 47 \\
  280.        16 & 53 & 59 & 61 & 67 & 71 \\
  281.        21 & 73 & 79 & 83 & 89 & 97 \\
  282.        26 & 101 & 103 & 107 & 109 & 113 \\
  283.        31 & 127 & 131 & 137 & 139 & 149 \\
  284.        36 & 151 & 157 & 163 & 167 & 173 \\
  285.        41 & 179 & 181 & 191 & 193 & 197 \\
  286.        46 & 199 & 211 & 223 & 227 & 229
  287.    \end{tabular}
  288. \end{center}
  289.  
  290. Very large prime numbers:\\
  291. \begin{tabular}{ccc}
  292.    1000001333 & 1000500889 & 2500001909 \\
  293.    2000000659 & 900004151 & 850001359
  294. \end{tabular}
  295.  
  296.  
  297.  
  298. \end{document}
  299.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement