求调代码
查看原帖
求调代码
724600
Submerge_TA楼主2023/7/15 18:53
#include <iostream>
#include <vector>
#include <map>
using namespace std;

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

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    map<int, int> count;

    for (int i = 0; i < n; i++) {
        count[a[i]]++;
    }

    int maxCount = 0;
    int maxCountCount = 0;
    for (auto it = count.begin(); it != count.end(); it++) {
        if (it->second > maxCount) {
            maxCount = it->second;
            maxCountCount = 1;
        } else if (it->second == maxCount) {
            maxCountCount++;
        }
    }

    if (maxCount >= (n + 1) / 2) {
        cout << "pigstd" << endl;
        return 0;
    }

    if (k >= 1) {
        cout << "pigstd"<< endl;
        return 0;
    }

    if (maxCount + k >= (n + 1) / 2) {
        cout << 1 << endl;
        return 0;
    }

    cout << maxCountCount << endl;

    return 0;
}
2023/7/15 18:53
加载中...