跳到正文

题解

CF1007A题解

lkrqwq约 1 分钟
原文
文章信息与版本

文章信息

发布
2023年9月17日
收录
2025年12月12日
更新
2026年11月22日
篇幅
约 1 分钟
题目
CF1007A

版本

  1. v1当前

这道题太水了,实现原理很简单:

  • 输入 nn 个数,并且用 countcount 记录每一个数的出现次数。
  • 用数组长度减去出现次数最多的元素的次数,即是答案。

AC代码:

C++
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

int main() {
    int n;
    cin >> n;

    vector<int> arr(n);
    unordered_map<int, int> cnt;

    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
        cnt[arr[i]]++;//记录元素出现次数
    }

    int maxcnt = 0;

    for (const auto& pair : cnt) {
        maxcnt = max(maxcnt, pair.second);//寻找出现次数最多的元素的次数
    }

    int maxans = n - maxcnt;

    cout << maxans << endl;

    return 0;
    //求过!
}

原文