#include <iostream> #include <algorithm> #include <vector> int main() { int occ[500010]; int n, r; std::cin >> n; for (int i = 1; i <= n; i++) { occ[i] = 0; } for (int i = 0; i < n; i++) { std::cin >> r; occ[r]++; } std::vector<int> occvec(occ, occ + n + 1); std::sort(occvec.begin(), occvec.end()); int res = 0; while (n > 0) { res++; n -= (occvec[occvec.size() - res] * 2 - 1); } std::cout << 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 | #include <iostream> #include <algorithm> #include <vector> int main() { int occ[500010]; int n, r; std::cin >> n; for (int i = 1; i <= n; i++) { occ[i] = 0; } for (int i = 0; i < n; i++) { std::cin >> r; occ[r]++; } std::vector<int> occvec(occ, occ + n + 1); std::sort(occvec.begin(), occvec.end()); int res = 0; while (n > 0) { res++; n -= (occvec[occvec.size() - res] * 2 - 1); } std::cout << res; return 0; } |