Skip to content

Commit eaa1792

Browse files
xian18colinaaa
andauthored
骨牌问题和稳定匹配 (#15)
* finish stable matching * feat(ref): change all ref to autoref and add ref for netflow * feat(ref): use autoref instead of ref * style: reformat new sources Co-authored-by: Colin <colinwang.0616@gmail.com>
1 parent 196a18f commit eaa1792

4 files changed

Lines changed: 358 additions & 2 deletions

File tree

book.tex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
\documentclass[cn]{elegantbook}
1+
\documentclass[cn,table]{elegantbook}
22

33
\usepackage{tikz}
44
\usepackage{graphicx}
@@ -7,12 +7,16 @@
77
\usepackage{hyperref}
88
\usepackage{listings}
99
\usepackage{interval}
10+
\usepackage{xcolor}
11+
\usepackage{ulem}
12+
\usepackage{wrapfig}
1013

1114
\intervalconfig{%
1215
soft open fences,
1316
}
1417

1518
\def\figureautorefname{图}
19+
\def\sectionautorefname{小节}
1620

1721
\SetAlgorithmName{算法}{算法}{算法索引}
1822

@@ -35,6 +39,8 @@
3539
% add your code here
3640
% \input{src/example.tex}
3741
\input{src/Ln1-AsymptoticOrderGrowth.tex}
42+
\input{src/Tiling-Problem.tex}
43+
\input{src/stable-matching.tex}
3844
\input{src/Ln9-NearestPoints.tex}
3945
\input{src/Ln11-LargeIntegerMultiplication.tex}
4046
\input{src/dynamic-programming-1.tex}

src/Network-flows.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ \section{最大二分匹配问题}
9191
\item 因此,逆否命题成立,霍尔定理得证。
9292
\end{itemize}
9393

94-
\section{骨牌问题}
94+
\section{骨牌问题}\label{sec:network-flows-tiling}
9595
回顾本课程开头提到的骨牌问题,我们试着用网络流的方法再次解决。
9696
\begin{example}
9797
\(m \times n\)的残缺棋盘(有方格缺失)上,填入\(1 \times 2\)大小的矩形骨牌,能否用骨牌将棋盘填满?

src/Tiling-Problem.tex

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
\chapter{骨牌问题 (Tiling Problem)}
2+
3+
\begin{introduction}
4+
\item 定义
5+
\item 形状为$2\times1$的骨牌
6+
\end{introduction}
7+
8+
\section{问题定义}\label{sec:tiling-1}
9+
\begin{definition}{骨牌问题}{def:tiling-problem}
10+
给出大小确定数量不限的骨牌,问能否不重叠的铺满整个平面
11+
\end{definition}
12+
13+
\section{骨牌形状为\texorpdfstring{$2\times1$}{}}\label{sec:tiling-2}
14+
骨牌形状为$2\times1$(如\autoref{fig:tiling-1}),判断使用该种骨牌能不能不重叠的铺满给定的平面。
15+
形状为$2\times1$的骨牌的填充问题属于$P$类问题。
16+
下面是一些用这种骨牌填充的例题。
17+
\begin{figure}[hbt!]
18+
\centering
19+
\begin{tabular}{|c|}
20+
\hline
21+
\\ \hline
22+
\\ \hline
23+
\end{tabular}
24+
\caption{形状为$2\times1$的骨牌}
25+
\label{fig:tiling-1}
26+
\end{figure}
27+
\subsection{形状为\texorpdfstring{$M\times N$}{}的矩形}\label{subsec:tiling-2-1}
28+
这种完整的矩形(如\autoref{fig:tiling-2})是简单问题。只需要判断形状中的格子数目($M\times N$)是否为偶数。
29+
如果格子的数目为偶数,则能填满。
30+
如果格子的数目为奇数则不能填满。
31+
\begin{figure}[hbt!]
32+
\centering
33+
\begin{tabular}{|c|c|c|c@{\dots}c|c|c|c|}
34+
\cline{1-3} \cline{6-8}
35+
& & & & & & & \\
36+
\cline{1-3} \cline{6-8}
37+
& & & & & & & \\
38+
\cline{1-3} \cline{6-8}
39+
\multicolumn{3}{c}{} & & \multicolumn{3}{c}{} \\
40+
\cline{1-3} \cline{6-8}
41+
& & & & & & & \\
42+
\cline{1-3} \cline{6-8}
43+
& & & & & & & \\
44+
\cline{1-3} \cline{6-8}
45+
\end{tabular}
46+
\caption{$M\times N$的矩形}\label{fig:tiling-2}
47+
\end{figure}
48+
49+
50+
如果格子的数目为奇数,显然不能使用$2\times1$的骨牌铺满。而当格子的数目为偶数时,则行或列中必有一个为偶数。显然能用这种骨牌填满。
51+
\subsection{形状为$6\times6$的矩形挖去两个对角}\label{subsec:tiling-2-2}
52+
\begin{figure}[ht!]
53+
\begin{subfigure}{0.5\textwidth}
54+
\centering
55+
\begin{tabular}{|c|c|c|c|c|c|}
56+
\cline{2-6}
57+
\multicolumn{1}{c|}{} & & & & & \\ \hline
58+
& & & & & \\ \hline
59+
& & & & & \\ \hline
60+
& & & & & \\ \hline
61+
& & & & & \\ \hline
62+
& & & & & \multicolumn{1}{c}{} \\
63+
\cline{1-5}
64+
\end{tabular}
65+
\caption{挖去两个对角的$6\times6$的矩形}\label{fig:tiling-3}
66+
\end{subfigure}
67+
\begin{subfigure}{0.5\textwidth}
68+
\centering
69+
\begin{tabular}{|c|c|c|c|c|c|}
70+
\cline{2-6}
71+
\multicolumn{1}{c|}{} & \cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} \\ \hline
72+
\cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} & \\ \hline
73+
& \cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} \\ \hline
74+
\cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} & \\ \hline
75+
& \cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} \\ \hline
76+
\cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} & \multicolumn{1}{c}{} \\
77+
\cline{1-5}
78+
\end{tabular}
79+
\caption{染色后的矩形}\label{fig:tiling-4}
80+
\end{subfigure}
81+
\caption{}
82+
\end{figure}
83+
这种情况下(如\autoref{fig:tiling-3}),格子的总数为34个,是个偶数。所以可以尝试通过对格子进行染色的方式判断。选取其中一个格子染成和黑色,
84+
对黑色上下左右相邻的格子染成白色,对白色上下左右相邻的格子染成黑色(结果如\autoref{fig:tiling-4})。染色是判断能否被填充的一个方法。
85+
这种方法得到的不可填充的结论是可信的,但可填充的结论却不一定可信。
86+
87+
统计黑色和白色格子的数目,黑色有18个,白色有16个。而将骨牌染成黑白两色,发现需要被填充的形状中黑色和白色的个数不同。所以这种形状无法被$2\times1$的骨牌填充。
88+
\subsection{一个奇异的形状}\label{subsec:tiling-2-3}
89+
\begin{figure}[h!]
90+
\begin{subfigure}{0.5\textwidth}
91+
\centering
92+
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|}
93+
\cline{2-4} \cline{7-9}
94+
\multicolumn{1}{c|}{} & & & & \multicolumn{1}{c}{} & \multicolumn{1}{c|}{} & & & & \multicolumn{1}{c}{} \\ \hline
95+
& & & & & & & & & \\ \hline
96+
& & & & & & & & & \\ \hline
97+
& & & & & & & & & \\ \hline
98+
\multicolumn{1}{c|}{} & & & & \multicolumn{1}{c}{} & \multicolumn{1}{c|}{} & & & & \multicolumn{1}{c}{} \\
99+
\cline{2-4} \cline{7-9}
100+
\end{tabular}
101+
\caption{一个例子}\label{fig:tiling-5}
102+
\end{subfigure}
103+
\begin{subfigure}{0.5\textwidth}
104+
\centering
105+
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|}
106+
\multicolumn{5}{c!{\color[rgb]{1,0,0}\vline}}{} & \multicolumn{5}{c}{} \\
107+
\cline{2-4} \cline{7-9}
108+
\multicolumn{1}{c|}{} & \cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} & \multicolumn{1}{c!{\color[rgb]{1,0,0}\vline}}{} & \multicolumn{1}{c|}{} & & \cellcolor[rgb]{0,0,0} & & \multicolumn{1}{c}{} \\ \hline
109+
\cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} & & \multicolumn{1}{c!{\color[rgb]{1,0,0}\vline}}{\cellcolor[rgb]{0,0,0}} & & \cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} & \\ \hline
110+
& \cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} & \multicolumn{1}{c!{\color[rgb]{1,0,0}\vline}}{} & \cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} \\ \hline
111+
\cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} & & \multicolumn{1}{c!{\color[rgb]{1,0,0}\vline}}{\cellcolor[rgb]{0,0,0}} & & \cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} & \\ \hline
112+
\multicolumn{1}{c|}{} & \cellcolor[rgb]{0,0,0} & & \cellcolor[rgb]{0,0,0} & \multicolumn{1}{c!{\color[rgb]{1,0,0}\vline}}{} & \multicolumn{1}{c|}{} & & \cellcolor[rgb]{0,0,0} & & \multicolumn{1}{c}{} \\
113+
\cline{2-4} \cline{7-9}
114+
\multicolumn{5}{c!{\color[rgb]{1,0,0}\vline}}{} & \multicolumn{5}{c}{}
115+
\end{tabular}
116+
\caption{染色后}\label{fig:tiling-6}
117+
\end{subfigure}
118+
\end{figure}
119+
在这种情况下(如\autoref{fig:tiling-5}),使用上述方式染色后(如\autoref{fig:tiling-6})发现黑色与白色的块数相同,均为21块。但这个图形却是不可被填充的。
120+
121+
现假设骨牌能填充这个形状,那么红线左侧和红线右侧都应该是可以被填充满的。但红线左侧的黑色方块比白色方块多4个,需要从右面借4个白色方块才能使左红线侧的褐色方块与白色方块数目相同。
122+
但红线右侧在不借出黑色方块的情况下最多借出2个白色方块,不满足需求。因此左边是不可能被填满的。所以整个平面也是不可被填满的。
123+
124+
这个问题还可以用网络流来求解。详见\autoref{sec:network-flows-tiling}。

0 commit comments

Comments
 (0)