diff --git a/codebook/4_Flow_Matching/Model.tex b/codebook/4_Flow_Matching/Model.tex index d9fee6d3..73a30650 100644 --- a/codebook/4_Flow_Matching/Model.tex +++ b/codebook/4_Flow_Matching/Model.tex @@ -1,34 +1,34 @@ % \normalsize \begin{itemize} - \itemsep-0.3em + %\itemsep-0.3em \item Maximum/Minimum flow with lower bound / Circulation problem - \vspace{-1em} + %\vspace{-1em} \begin{enumerate} - \itemsep-0.3em + %\itemsep-0.3em \item Construct super source $S$ and sink $T$. \item For each edge $(x, y, l, u)$, connect $x \rightarrow y$ with capacity $u - l$. \item For each vertex $v$, denote by $in(v)$ the difference between the sum of incoming lower bounds and the sum of outgoing lower bounds. \item If $in(v) > 0$, connect $S \rightarrow v$ with capacity $in(v)$, otherwise, connect $v \rightarrow T$ with capacity $-in(v)$. \begin{itemize} - \itemsep-0.2em + %\itemsep-0.2em \item To maximize, connect $t \rightarrow s$ with capacity $\infty$ (skip this in circulation problem), and let $f$ be the maximum flow from $S$ to $T$. If $f \neq \sum_{v \in V, in(v) > 0}{in(v)}$, there's no solution. Otherwise, the maximum flow from $s$ to $t$ is the answer. \item To minimize, let $f$ be the maximum flow from $S$ to $T$. Connect $t \rightarrow s$ with capacity $\infty$ and let the flow from $S$ to $T$ be $f^\prime$. If $f + f^\prime \neq \sum_{v \in V, in(v) > 0}{in(v)}$, there's no solution. Otherwise, $f^\prime$ is the answer. \end{itemize} \item The solution of each edge $e$ is $l_e + f_e$, where $f_e$ corresponds to the flow of edge $e$ on the graph. \end{enumerate} \item Construct minimum vertex cover from maximum matching $M$ on bipartite graph $(X, Y)$ - \vspace{-1em} + %\vspace{-1em} \begin{enumerate} - \itemsep-0.3em + %\itemsep-0.3em \item Redirect every edge: $y \rightarrow x$ if $(x, y) \in M$, $x \rightarrow y$ otherwise. \item DFS from unmatched vertices in $X$. \item $x \in X$ is chosen iff $x$ is unvisited. \item $y \in Y$ is chosen iff $y$ is visited. \end{enumerate} \item Minimum cost cyclic flow - \vspace{-0.5em} + %\vspace{-0.5em} \begin{enumerate} - \itemsep-0.3em + %\itemsep-0.3em \item Consruct super source $S$ and sink $T$ \item For each edge $(x, y, c)$, connect $x \rightarrow y$ with $(cost, cap) = (c, 1)$ if $c > 0$, otherwise connect $y \rightarrow x$ with $(cost, cap) = (-c, 1)$ \item For each edge with $c < 0$, sum these cost as $K$, then increase $d(y)$ by 1, decrease $d(x)$ by 1 @@ -37,9 +37,9 @@ \item Flow from $S$ to $T$, the answer is the cost of the flow $C + K$ \end{enumerate} \item Maximum density induced subgraph - \vspace{-1em} + %\vspace{-1em} \begin{enumerate} - \itemsep-0.3em + %\itemsep-0.3em \item Binary search on answer, suppose we're checking answer $T$ \item Construct a max flow model, let $K$ be the sum of all weights \item Connect source $s \rightarrow v$, $v \in G$ with capacity $K$ @@ -48,25 +48,25 @@ \item $T$ is a valid answer if the maximum flow $f < K \lvert V \rvert$ \end{enumerate} \item Minimum weight edge cover - \vspace{-1em} + %\vspace{-1em} \begin{enumerate} - \itemsep-0.3em + %\itemsep-0.3em \item For each $v \in V$ create a copy $v^\prime$, and connect $u^\prime \to v^\prime$ with weight $w(u, v)$. \item Connect $v \to v^\prime$ with weight $2\mu(v)$, where $\mu(v)$ is the cost of the cheapest edge incident to $v$. \item Find the minimum weight perfect matching on $G^\prime$. \end{enumerate} \item Project selection problem - \vspace{-1em} + %\vspace{-1em} \begin{enumerate} - \itemsep-0.3em + %\itemsep-0.3em \item If $p_v > 0$, create edge $(s, v)$ with capacity $p_v$; otherwise, create edge $(v, t)$ with capacity $-p_v$. \item Create edge $(u, v)$ with capacity $w$ with $w$ being the cost of choosing $u$ without choosing $v$. \item The mincut is equivalent to the maximum profit of a subset of projects. \end{enumerate} \item Dual of minimum cost maximum flow - \vspace{-1em} + %\vspace{-1em} \begin{enumerate} - \itemsep-0.3em + %\itemsep-0.3em \item Capacity $c_{uv}$, Flow $f_{uv}$, Cost $w_{uv}$, Required Flow difference for vertex $b_u$. \item If all $w_{uv}$ are integers, then optimal solution can happen when all $p_u$ are integers. \end{enumerate} @@ -76,11 +76,11 @@ \begin{aligned}\min\sum_{u} b_up_u + \sum_{uv}c_{uv}\max(0, p_v - p_u - w_{uv}) \\ p_u \geq 0 \end{aligned} $$ %\item 0/1 quadratic programming - %\vspace{-1em} + %%\vspace{-1em} %\[ \sum_x{c_xx} + \sum_y{c_y\bar{y}} + \sum_{xy}c_{xy}x\bar{y} + \sum_{xyx^\prime y^\prime}c_{xyx^\prime y^\prime}(x\bar{y} + x^\prime\bar{y^\prime}) \] %can be minimized by the mincut of the following graph: %\begin{enumerate} - % \itemsep-0.3em + % %\itemsep-0.3em % \item Create edge $(x, t)$ with capacity $c_x$ and create edge $(s, y)$ with capacity $c_y$. % \item Create edge $(x, y)$ with capacity $c_{xy}$. % \item Create edge $(x, y)$ and edge $(x^\prime, y^\prime)$ with capacity $c_{xyx^\prime y^\prime}$. diff --git a/codebook/6_Math/Estimation.tex b/codebook/6_Math/Estimation.tex index 4bab193e..96db511e 100644 --- a/codebook/6_Math/Estimation.tex +++ b/codebook/6_Math/Estimation.tex @@ -2,7 +2,7 @@ \item Estimation \begin{itemize} - \itemsep-0.5em + %\itemsep-0.5em \item The number of divisors of $n$ is at most around $100$ for $n<5e4$, $500$ for $n<1e7$, $2000$ for $n<1e10$, $200000$ for $n<1e19$. \item The number of ways of writing $n$ as a sum of positive integers, disregarding the order of the summands. $1, 1, 2, 3, 5, 7, 11, 15, 22, 30$ for $n=0\sim 9$, $627$ for $n=20$, $\sim 2e5$ for $n=50$, $\sim 2e8$ for $n=100$. \item Total number of partitions of $n$ distinct elements: $B(n)=1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975, 678570, 4213597,$\\ diff --git a/codebook/6_Math/Euclidean.tex b/codebook/6_Math/Euclidean.tex index a23127d8..313b354c 100644 --- a/codebook/6_Math/Euclidean.tex +++ b/codebook/6_Math/Euclidean.tex @@ -1,5 +1,5 @@ \begin{itemize} - \itemsep-0.5em + %\itemsep-0.5em \item $m = \lfloor\frac{an + b}{c}\rfloor$ \item Time complexity: $O(\log{n})$ \end{itemize} diff --git a/codebook/6_Math/Generating_function.tex b/codebook/6_Math/Generating_function.tex index 32815635..1c0846bf 100644 --- a/codebook/6_Math/Generating_function.tex +++ b/codebook/6_Math/Generating_function.tex @@ -2,7 +2,7 @@ \item Ordinary Generating Function $A(x) = \sum_{i\ge 0} a_ix^i$ \begin{itemize} - \itemsep-0.5em + %\itemsep-0.5em \item $A(rx) \Rightarrow r^na_n$ \item $A(x) + B(x) \Rightarrow a_n + b_n$ \item $A(x)B(x) \Rightarrow \sum_{i=0}^{n} a_ib_{n-i}$ @@ -13,7 +13,7 @@ \item Exponential Generating Function $A(x) = \sum_{i\ge 0} \frac{a_i}{i!}x_i$ \begin{itemize} - \itemsep-0.5em + %\itemsep-0.5em \item $A(x) + B(x) \Rightarrow a_n + b_n$ \item $A^{(k)}(x) \Rightarrow a_{n+k}$ \item $A(x)B(x) \Rightarrow \sum_{i=0}^{n} \binom{n}{i}a_ib_{n-i}$ @@ -22,7 +22,7 @@ \end{itemize} \item Special Generating Function \begin{itemize} - \itemsep-0.5em + %\itemsep-0.5em \item $(1+x)^n = \sum_{i\ge 0} \binom{n}{i}x^i$ \item $\frac{1}{(1-x)^n} = \sum_{i\ge 0} \binom{i}{n-1}x^i$ \end{itemize} diff --git a/codebook/6_Math/SimplexConstruction.tex b/codebook/6_Math/SimplexConstruction.tex index 889ea02b..8c9fb959 100644 --- a/codebook/6_Math/SimplexConstruction.tex +++ b/codebook/6_Math/SimplexConstruction.tex @@ -4,13 +4,13 @@ $\bar{\mathbf{x}}$ and $\bar{\mathbf{y}}$ are optimal if and only if for all $i \in [1, n]$, either $\bar{x}_i = 0$ or $\sum_{j=1}^{m}A_{ji}\bar{y}_j = c_i$ holds and for all $i \in [1, m]$ either $\bar{y}_i = 0$ or $\sum_{j=1}^{n}A_{ij}\bar{x}_j = b_j$ holds. \begin{enumerate} - \itemsep-0.5em + %\itemsep-0.5em \item In case of minimization, let $c^\prime_i = -c_i$ \item $\sum_{1 \leq i \leq n}{A_{ji}x_i} \geq b_j \rightarrow \sum_{1 \leq i \leq n}{-A_{ji}x_i} \leq -b_j$ \item $\sum_{1 \leq i \leq n}{A_{ji}x_i} = b_j$ - \vspace{-0.5em} + %\vspace{-0.5em} \begin{itemize} - \itemsep-0.5em + %\itemsep-0.5em \item $\sum_{1 \leq i \leq n}{A_{ji}x_i} \leq b_j$ \item $\sum_{1 \leq i \leq n}{A_{ji}x_i} \geq b_j$ \end{itemize} diff --git a/codebook/6_Math/Theorem.tex b/codebook/6_Math/Theorem.tex index 0c86287d..1ec442eb 100644 --- a/codebook/6_Math/Theorem.tex +++ b/codebook/6_Math/Theorem.tex @@ -15,7 +15,7 @@ Denote $L$ be a $n \times n$ matrix as the Laplacian matrix of graph $G$, where $L_{ii} = d(i)$, $L_{ij} = -c$ where $c$ is the number of edge $(i, j)$ in $G$. \begin{itemize} - \itemsep-0.5em + %\itemsep-0.5em \item The number of undirected spanning in $G$ is $\lvert \det(\tilde{L}_{11}) \rvert$. \item The number of directed spanning tree rooted at $r$ in $G$ is $\lvert \det(\tilde{L}_{rr}) \rvert$. \end{itemize} @@ -27,7 +27,7 @@ \item Cayley's Formula \begin{itemize} - \itemsep-0.5em + %\itemsep-0.5em \item Given a degree sequence $d_1, d_2, \ldots, d_n$ for each \textit{labeled} vertices, there are $\frac{(n - 2)!}{(d_1 - 1)!(d_2 - 1)!\cdots(d_n - 1)!}$ spanning trees. \item Let $T_{n, k}$ be the number of \textit{labeled} forests on $n$ vertices with $k$ components, such that vertex $1, 2, \ldots, k$ belong to different components. Then $T_{n, k} = kn^{n - k - 1}$. \end{itemize} @@ -47,7 +47,7 @@ \item Möbius inversion formula \begin{itemize} - \itemsep-0.5em + %\itemsep-0.5em \item $f(n)=\sum_{d\mid n}g(d)\Leftrightarrow g(n)=\sum_{d\mid n}\mu(d)f(\frac{n}{d})$ \item $f(n)=\sum_{n\mid d}g(d)\Leftrightarrow g(n)=\sum_{n\mid d}\mu(\frac{d}{n})f(d)$ \end{itemize} @@ -55,7 +55,7 @@ \item Spherical cap \begin{itemize} - \itemsep-0.5em + %\itemsep-0.5em \item A portion of a sphere cut off by a plane. \item $r$: sphere radius, $a$: radius of the base of the cap, $h$: height of the cap, $\theta$: $\arcsin(a/r)$. \item Volume $=\pi h^2(3r-h)/3=\pi h(3a^2+h^2)/6=\pi r^3(2+\cos\theta)(1-\cos\theta)^2/3$. @@ -65,7 +65,7 @@ \item Lagrange multiplier \begin{itemize} - \itemsep-0.5em + %\itemsep-0.5em \item Optimize $f(x_1, \ldots, x_n)$ when $k$ constraints $g_i(x_1, \ldots, x_n)=0$. \item Lagrangian function $\mathcal{L}(x_1, \ldots, x_n, \lambda_1, \ldots, \lambda_k) = f(x_1, \ldots, x_n) = \sum^{k}_{i=1}\lambda_i g_i(x_1, \ldots, x_n)$. \item The solution corresponding to the original constrained optimization is always a saddle point of the Lagrangian function. diff --git a/codebook/9_Else/Matroid.tex b/codebook/9_Else/Matroid.tex index ee862ad5..e83c1ad4 100644 --- a/codebook/9_Else/Matroid.tex +++ b/codebook/9_Else/Matroid.tex @@ -1,14 +1,14 @@ Start from $S = \emptyset$. In each iteration, let -\vspace{-0.5em} +%\vspace{-0.5em} \begin{itemize} - \itemsep-0.5em + %\itemsep-0.5em \item $Y_1 = \{x \not\in S \mid S \cup \{x\} \in I_1 \}$ \item $Y_2 = \{x \not\in S \mid S \cup \{x\} \in I_2 \}$ \end{itemize} If there exists $x \in Y_1 \cap Y_2$, insert $x$ into $S$. Otherwise for each $x \in S, y \not\in S$, create edges -\vspace{-0.5em} +%\vspace{-0.5em} \begin{itemize} - \itemsep-0.5em + %\itemsep-0.5em \item $x \to y$ if $S - \{x\} \cup \{y\} \in I_1$. \item $y \to x$ if $S - \{x\} \cup \{y\} \in I_2$. \end{itemize} diff --git a/codebook/9_Else/Mos_Algorithm.tex b/codebook/9_Else/Mos_Algorithm.tex index 21d93a21..4e5ed540 100644 --- a/codebook/9_Else/Mos_Algorithm.tex +++ b/codebook/9_Else/Mos_Algorithm.tex @@ -2,7 +2,7 @@ \item Mo's Algorithm With Addition Only \begin{itemize} - \itemsep-0.5em + %\itemsep-0.5em \item Sort querys same as the normal Mo's algorithm. \item For each query $[l, r]$: \item If $l / blk = r / blk$, brute-force. @@ -14,7 +14,7 @@ \item Mo's Algorithm With Offline Second Time \begin{itemize} - \itemsep-0.5em + %\itemsep-0.5em \item Require: Changing answer $\equiv$ adding $f([l, r], r + 1)$. \item Require: $f([l, r], r + 1) = f([1, r], r + 1) - f([1, l), r + 1)$. \item Part1: Answer all $f([1, r], r + 1)$ first. diff --git a/codebook/codebook.tex b/codebook/codebook.tex index b0fa9fc0..fcf6e11e 100644 --- a/codebook/codebook.tex +++ b/codebook/codebook.tex @@ -13,9 +13,11 @@ \usepackage{fancyhdr} %設定頁首頁尾 \usepackage{graphicx} %Graphic \usepackage{enumerate} +\usepackage{multicol} \usepackage{titlesec} \usepackage{amsmath} \usepackage[CheckSingle, CJKmath]{xeCJK} +\usepackage{savetrees} % \usepackage{CJKulem} %\usepackage[T1]{fontenc} @@ -33,7 +35,8 @@ \evensidemargin=0pt \hoffset=-42pt -\titlespacing\subsection{0pt}{4pt plus 2pt minus 2pt}{0pt plus 2pt minus 2pt} +\titlespacing\section{0pt}{0pt plus 2pt minus 2pt}{0pt plus 2pt minus 2pt} +\titlespacing\subsection{0pt}{0pt plus 2pt minus 2pt}{0pt plus 2pt minus 2pt} %\renewcommand\listfigurename{圖目錄} @@ -41,12 +44,8 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\setmainfont{Consolas} %主要字型 -%\setmonofont{Monaco} %主要字型 -\setmonofont{Consolas} -\setCJKmainfont{Noto Sans CJK TC} -% \setCJKmainfont{Consolas} %中文字型 -%\setmainfont{sourcecodepro} +\setmainfont{Ubuntu} %主要字型 +\setmonofont{Ubuntu Mono} \XeTeXlinebreaklocale "zh" %中文自動換行 \XeTeXlinebreakskip = 0pt plus 1pt %設定段落之間的距離 \setcounter{secnumdepth}{3} %目錄顯示第三層 @@ -125,7 +124,9 @@ \renewcommand{\contentsname}{Contents} \scriptsize -\tableofcontents +\begin{multicols}{2} + \tableofcontents +\end{multicols} %%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\newpage