HBC200160What Goes Up Must Come Down题解

凸凸曼凸凸 算法基础篇 62 0
挑战自我,勇攀编程高峰!全网最全C++题库,助您成为编程达人。
Several cards with numbers printed on them are lined up on the table. We’d like to change their order so that rst some are in non-decreasing order of the numbers on them, and the rest are in non-increasing order. For example, , , and are acceptable orders, but and are not. To put it formally, with n the number of cards and bi the number printed on the card at the i-th position after reordering, there should exist k∈{1,…,n1})left text { and }left(bi≤bi+1∨i∈{1,…,n1}) hold. For reordering, the only operation allowed at a time is to swap the positions of an adjacent card pair. We want to know the minimum number of swaps required to complete the reorder.

Several cards with numbers printed on them are lined up on the table. We’d like to change their order so that first some are in non-decreasing order of the numbers on them, and the rest are in non-increasing order. For example, (1, 2, 3, 2, 1), (1, 1, 3, 4, 5, 9, 2), and (5, 3, 1) are acceptable orders, but (8, 7, 9) and (5, 3, 5, 3) are not. To put it formally, with n the number of cards and bi the number printed on the card at the i-th position (1≤i≤n)(1 leq i leq n)(1≤i≤n) after reordering, there should exist k∈{1,…,n}k in {1,dots,n }k∈{1,…,n} such that(bi≤bi+1∨i∈{1,…,k−1}) and (bi≥bi+1∨i∈{k,…,n−1})left(b_{i} leq b_{i+1} vee i in{1, ldots, k-1}right) text { and }left(b_{i} geq b_{i+1} vee i in{k, ldots, n-1}right)(bi​≤bi+1​∨i∈{1,…,k−1}) and (bi​≥bi+1​∨i∈{k,…,n−1}) hold. For reordering, the only operation allowed at a time is to swap the positions of an adjacent card pair. We want to know the minimum number of swaps required to complete the reorder.

HBC200160What Goes Up Must Come Down题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
成为编程大师,不再是梦想!全网最全C++题库,助您开启编程新篇章。

标签: HBC200160What Goes Up Must Come Down题解