#include <bits/stdc++.h> using namespace std; typedef vector<int> VI; typedef pair <int,int> ii; typedef long long LL; #define pb push_back const int INF = 2147483647; const int MOD = 1000000007; const int N = 500005; int n, i, a, tab[N], res, k; int main() { scanf("%d", &n); for (i=0;i<n;i++) { scanf("%d", &a); tab[a - 1]++; } sort(tab, tab + n); reverse(tab, tab + n); k = 0; res = 0; while (k < n) { k += (2 * tab[res] - 1); res++; } 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 | #include <bits/stdc++.h> using namespace std; typedef vector<int> VI; typedef pair <int,int> ii; typedef long long LL; #define pb push_back const int INF = 2147483647; const int MOD = 1000000007; const int N = 500005; int n, i, a, tab[N], res, k; int main() { scanf("%d", &n); for (i=0;i<n;i++) { scanf("%d", &a); tab[a - 1]++; } sort(tab, tab + n); reverse(tab, tab + n); k = 0; res = 0; while (k < n) { k += (2 * tab[res] - 1); res++; } printf("%d\n", res); return 0; } |