#include <cstdio> #include <vector> #include <algorithm> int main() { int n; scanf("%d", &n); std::vector<int> counter(n, 0); for (int i = 0; i < n; i++) { int x; scanf("%d", &x); counter[x - 1]++; } sort(counter.begin(), counter.end()); int s = 0; int r = 0; while (s < n) { s += 2 * counter[n - r - 1] - 1; r++; } printf("%d\n", r); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <cstdio> #include <vector> #include <algorithm> int main() { int n; scanf("%d", &n); std::vector<int> counter(n, 0); for (int i = 0; i < n; i++) { int x; scanf("%d", &x); counter[x - 1]++; } sort(counter.begin(), counter.end()); int s = 0; int r = 0; while (s < n) { s += 2 * counter[n - r - 1] - 1; r++; } printf("%d\n", r); return 0; } |