P1080 国王游戏
1.贪心思路
当两个大臣 q 1 q_1 q1 , q 2 q_2 q2 在国王( q 0 q_0 q0 )后又两种排列方式:
- q 0 q 1 q 2 q_0 q_1 q_2 q0q1q2
- q 0 q 2 q 1 q_0 q_2 q_1 q0q2q1
两种情况答案分别为以下算式
- a n s 1 = max ( a 0 b 1 , a 0 ⋅ a 1 b 2 ) ans_1=\max({\frac{a_0}{b_1}},{\frac{a_{0}\cdot a_1}{b_2}}) ans1=max(b1a0,b2a0⋅a1)
- a n s 2 = max ( a 0 b 2 , a 0 ⋅ a 2 b 1 ) ans_2=\max({\frac{a_0}{b_2}},{\frac{a_0 \cdot a_2}{b_1}}) ans2=max(b2a0,b1a0⋅a2)
明显可以看出:
{ a 0 ⋅ a 1 b 2 > a 0 b 2 a 0 ⋅ a 2 b 1 > a 0 b 1 \begin{cases}\frac{a_0\cdot a_1}{b_2}>\frac{a_0}{b_2}\\\frac{a_0\cdot a_2}{b_1}>\frac{a_0}{b_1}\end{cases} {b2a0⋅a1>b2a0b1a0⋅a2>b1a0
如果 a n s 1 < a n s 2 ans_1<ans_2 ans1<ans2 :
∵ ∵ ∵ a 0 ⋅ a 2 b 1 > a 0 b 1 \frac{a_0\cdot a_2}{b_1}>\frac{a_0}{b_1} b1a0⋅a2>b1a0
∴ ∴ ∴ a 0 ⋅ a 2 b 1 > a 0 ⋅ a 1 b 2 \frac{a_0\cdot a_2}{b_1}>\frac{a_0\cdot a_1}{b_2} b1a0⋅a2>b2a0⋅a1
↓
a 2 b 1 > a 1 b 2 \frac{a_2}{b_1}>\frac{a_1}{b_2} b1a2>b2a1
↓
a 1 ⋅ b 1 < a 2 ⋅ b 2 a_1\cdot b_1<a_2\cdot b_2 a1⋅b1<a2⋅b2
按照上述结论:
cmp ( q 1 , q 2 ) = { q 1 . a × q 1 . b < q 2 . a × q 2 . b t r u e q 1 . a × q 1 . b ≥ q 2 . a × q 2 . b f a l s e \operatorname{cmp}({q_1},{q_2})=\begin{cases}q_1.a\times q_1.b<q_2.a\times q_2.b&true\\q_1.a\times q_1.b\ge q_2.a\times q_2.b&false\end{cases} cmp(q1,q2)={q1.a×q1.b<q2.a×q2.bq1.a×q1.b≥q2.a×q2.btruefalse
按照该cmp排序并计算即可