Max and Min
题目描述
Two kittens, Max and Min, play with a pair of non-negative integers $x$ and $y$. As you can guess from their names, kitten Max loves to maximize and kitten Min loves to minimize. As part of this game Min wants to make sure that both numbers, $x$ and $y$ became negative at the same time, and kitten Max tries to prevent him from doing so.
Each kitten has a set of pairs of integers available to it. Kitten Max has $n$ pairs of non-negative integers $(a_i, b_i)$, and kitten Min has $m$ pairs of non-negative integers $(c_j, d_j)$. As kitten Max makes a move, it can take any available pair $(a_i, b_i)$ and add $a_i$ to $x$ and $b_i$ to $y$, and kitten Min can take any available pair $(c_j, d_j)$ and subtract $c_j$ from $x$ and $d_j$ from $y$. Each kitten can use each pair multiple times during distinct moves.
Max moves first. Kitten Min is winning if at some moment both numbers $a, b$ are negative simultaneously. Otherwise, the winner of the game is kitten Max. Determine which kitten wins if both of them play optimally.
题意概述
有两个人 Max 和 Min,初始时有两个数$x$和$y$。Max 有$n$个数对$(a_i, b_i)$,Min 有$m$个数对$(c_j, d_j)$。两个人轮流操作,Max 先手。Max 可以选择一个数对$(a_i, b_i)$,将$x$加上$a_i$、$y$加上$b_i$;Min 可以选择一个数对$(c_j, d_j)$,将$x$减去$c_j$、$y$减去$d_j$。若在某一时刻$x, y$同时为负,则 Min 获胜,否则 Max 获胜。求谁必胜。
数据范围:$1 \le n, m \le 10^5, \ 1 \le x, y, a_i, b_i, c_j, d_j \le 10^9$。
算法分析
对于两个向量$v_1, v_2$,我们用$(v_1, v_2)$表示$v_1 \cdot v_2$。
我们把所有数对看成从原点出发的向量。假设有一个新的向量$(a, b)$。若
$$
\begin{align}
&\exists (a, b), \ a, b \ge 0 \land a+b \gt 0, \\
&\exists (a_i, b_i), \ \forall (c_j, d_j), \ ((a_i, b_i), (a, b)) \ge ((c_j, d_j), (a, b))
\end{align}
$$
那么 Max 必胜。证明如下:
$\because$初始时$((x, y), (a, b))=ax+by \gt 0$
$((a_i-c_j, b_i-d_j), (a, b))=((a_i, b_i), (a, b))-((c_j, d_j), (a, b)) \ge 0$
$\therefore$在任意时刻$((x’, y’), (a, b)) \gt 0$
$\therefore x’, y’$不全为负数
由此得证。
若$\exists (c_{j_0}, d_{j_0}), (c_{j_1}, d_{j_1})$,点$(a_i, b_i)$严格在点$(c_{j_0}, d_{j_0})$、$(c_{j_1}, d_{j_1})$和原点所组成的三角形内部,那么根据上述证明,$(a_i, b_i)$对 Max 没有贡献。特别的,若
$$
\exists (c_j, d_j), \ (a_i, b_i) \parallel (c_j, d_j) \land |(a_i, b_i)| \lt |(c_j, d_j)|
$$
那么$(a_i, b_i)$也没有贡献。
算法已经很清晰了——对 Min 的向量求凸包,判断是否所有 Max 的向量都严格在凸包内部。假设 Min 的向量中$c_j$的最大值为$mx_c$,$d_j$的最大值为$mx_d$,凸包中还需加入三个点$(0, 0), (mx_c, 0), (0, mx_d)$。
具体实现时,可以将 Max 的向量拿来一起求凸包。若求出来的凸包上有 Max 的向量,则 Max 必胜,否则 Min 必胜。
代码
1 |
|