#include<iostream> #include<map> #include<iterator> #include<vector> #include<algorithm> int arr[500005]; int main() { std::map<int, int>m; std::vector<int>v; std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); int n,k; std::cin >> n; for (int i = 0; i < n; i++) { std::cin >> k; arr[k]++; } for (int i = 0; i < 500001; i++) { if (arr[i] > 0) { v.push_back(arr[i]); } } std::sort(v.begin(), v.end()); int u = (n +1)/ 2; int s = 0; int i = v.size() - 1; while (s < n) { s += (v[i] * 2 - 1); i--; } std::cout << v.size() - 1 - i; }
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 32 33 34 35 | #include<iostream> #include<map> #include<iterator> #include<vector> #include<algorithm> int arr[500005]; int main() { std::map<int, int>m; std::vector<int>v; std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); int n,k; std::cin >> n; for (int i = 0; i < n; i++) { std::cin >> k; arr[k]++; } for (int i = 0; i < 500001; i++) { if (arr[i] > 0) { v.push_back(arr[i]); } } std::sort(v.begin(), v.end()); int u = (n +1)/ 2; int s = 0; int i = v.size() - 1; while (s < n) { s += (v[i] * 2 - 1); i--; } std::cout << v.size() - 1 - i; } |