zoukankan      html  css  js  c++  java
  • [CF1490F] Equalize the Array

    [CF1490F] Equalize the Array

    Description

    给出序列问最少需要删除多少个元素,才可以使得剩余的序列中,所有不同数字出现的次数均相等。

    Solution

    从出现次数的角度考虑,对于一个元素,如果大于等于一个设定值 x,就把他变为 x,否则变为 0,要让最后的总和最大

    那么显然我们只需要枚举一下 x,统计大于等于 x 的数的个数 cnt,此时的答案就是 x cnt

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long
    
    void solve()
    {
        int n;
        cin >> n;
    
        map<int, int> mp;
        for (int i = 1; i <= n; i++)
        {
            int x;
            cin >> x;
            mp[x]++;
        }
    
        multiset<int> ms;
        for (auto [x, y] : mp)
            ms.insert(y);
    
        int ans = 0;
        for (int i = 1; i <= n; i++)
        {
            ms.erase(i - 1);
            ans = max(ans, static_cast<int>(ms.size() * i));
        }
        cout << n - ans << endl;
    }
    
    signed main()
    {
        ios::sync_with_stdio(false);
    
        int t;
        cin >> t;
        while (t--)
        {
            solve();
        }
    }
    
  • 相关阅读:
    MathML
    Redux counterpart rematch dva
    flow
    pauseable 库
    a simple machine learning system demo, for ML study.
    react图工具集成
    SQLite
    Celery
    RabbitMQ installation
    Thunk
  • 原文地址:https://www.cnblogs.com/mollnn/p/14432938.html
Copyright © 2011-2022 走看看