#include <bits/stdc++.h> using namespace std; const int MAX_N = 500000; int t[MAX_N + 9]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { int a; scanf("%d", &a); t[a]++; } vector<int> v; for (int i = 1; i <= n; ++i) { if (t[i]) { v.push_back(t[i]); } } sort(v.begin(), v.end()); int res = 0; while (n > 0) { res++; n -= v.back()*2 - 1; v.pop_back(); } printf("%d\n", res); 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 <bits/stdc++.h> using namespace std; const int MAX_N = 500000; int t[MAX_N + 9]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { int a; scanf("%d", &a); t[a]++; } vector<int> v; for (int i = 1; i <= n; ++i) { if (t[i]) { v.push_back(t[i]); } } sort(v.begin(), v.end()); int res = 0; while (n > 0) { res++; n -= v.back()*2 - 1; v.pop_back(); } printf("%d\n", res); return 0; } |