#include <bits/stdc++.h>
int main() {
int n;
std::cin >> n;
std::unordered_map<int, int> a;
for(int i = 0; i < n; i++) {
int x;
std::cin >> x;
a[x]++;
}
std::vector<int> counts;
for(auto p : a) {
counts.push_back(p.second);
}
std::sort(counts.begin(), counts.end());
int r = 0;
int total = 0;
while(total < n) {
r += 1;
total += 2 * (counts[counts.size() - r]) - 1;
}
std::cout << r << "\n";
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <bits/stdc++.h> int main() { int n; std::cin >> n; std::unordered_map<int, int> a; for(int i = 0; i < n; i++) { int x; std::cin >> x; a[x]++; } std::vector<int> counts; for(auto p : a) { counts.push_back(p.second); } std::sort(counts.begin(), counts.end()); int r = 0; int total = 0; while(total < n) { r += 1; total += 2 * (counts[counts.size() - r]) - 1; } std::cout << r << "\n"; } |
English