santisify Site

Back

Codeforces Round 967 (Div. 2)Blur image

A.Make All Equal#

题目描述#

{% tabs A %}

You are given a cyclic array a1,a2,,ana_1,a_2,…,a_n . You can perform the following operation on a at most n1n−1 times:

  • Let m be the current size of a, you can choose any two adjacent elements where the previous one is no greater than the latter one (In particular, ama_m and a1a_1 are adjacent and ama_m is the previous one), and delete exactly one of them. In other words, choose an integer i ( 1im1 \le i \le m ) where aia(imodm)+1a_i \le a_{(i \mod m)+1} holds, and delete exactly one of aia_i or a(imodm)+1a_{(i \mod m) + 1} from aa. Your goal is to find the minimum number of operations needed to make all elements in aa equal.

题目意思是想让我们用最少的操作次数删除数组中的元素获得数组中的数字全相等的数组。

{% endtabs %}

解题思路#

由于需要最小的操作数,我们可以直接剩下数目最多的数字,于是就可以使用 STL 中的 map 完成此题

参考代码#

Codeforces Round 967 (Div. 2)
https://santisify.top/blog/old/cf2001
Author santisify
Published at September 2, 2024
Comment seems to stuck. Try to refresh?✨