P4642 [BJWC2008] 方程 题解
PlatinumBessieS
·
·
题解
简单线性规划。
问题要求求解以下的线性规划:
\begin{aligned}
\max &\hspace{0.1cm} \sum\limits_{i = 1}^n C_i x_i \\
\text{subject to} &\hspace{0.1cm} \sum\limits_{i = 1}^n A_i x_i = S, \\
&\hspace{0.1cm} \sum\limits_{i = 1}^n B_i x_i = T, \\
&\hspace{0.1cm} \forall i \in [1, n] \land i \in \Z, x_i \geq 0. \\
\end{aligned}
显然其等价于:
\begin{aligned}
\max &\hspace{0.1cm} \sum\limits_{i = 1}^n C_i x_i \\
\text{subject to} &\hspace{0.1cm} \sum\limits_{i = 1}^n A_i x_i \leq S, \\
&\hspace{0.1cm} \sum\limits_{i = 1}^n B_i x_i \leq T, \\
&\hspace{0.1cm} -\sum\limits_{i = 1}^n A_i x_i \leq -S, \\
&\hspace{0.1cm} -\sum\limits_{i = 1}^n B_i x_i \leq -T, \\
&\hspace{0.1cm} \forall i \in [1, n] \land i \in \Z, x_i \geq 0. \\
\end{aligned}
直接跑单纯形法肯定不行,套路地对偶一下:
\begin{aligned}
\min &\hspace{0.1cm} S(x - x') + T(y - y') \\
\text{subject to} &\hspace{0.1cm} \forall i \in [1, n] \land i \in \Z, A_i (x - x') + B_i (y - y') \geq C_i, \\
&\hspace{0.1cm} x \geq 0, \\
&\hspace{0.1cm} y \geq 0, \\
&\hspace{0.1cm} x' \geq 0, \\
&\hspace{0.1cm} y' \geq 0. \\
\end{aligned}
显然其可以简化为:
\begin{aligned}
\min &\hspace{0.1cm} Sx + Ty \\
\text{subject to} &\hspace{0.1cm} \forall i \in [1, n] \land i \in \Z, y \geq -\frac{A_i}{B_i}x + \frac{C_i}{B_i}. \\
\end{aligned}
注意到该线性规划是二元的,考虑使用最朴素的作图法解决,即使用半平面交。考虑如何处理询问。容易发现,询问相当于要求找到与该半平面交有交的斜率为 -\frac{S}{T} 的直线的截距最小值。离线并将询问依此排序后容易完成。