#include <bits/stdc++.h> #define ll long long #define fors(u, n, s) for(ll u = (s); u < (n); u++) #define foru(u, n) fors(u, n, 0) #define vec vector #define pb push_back #define f first #define s second #define ir(a, b, x) (((a) <= (x)) && ((x) <= (b))) #define pint pair<ll, ll> using namespace std; const int N = 6e5; int n; int a[N]; int cnt[N]; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> n; foru(i, n) cin >> a[i]; foru(i, n) cnt[a[i]]++; sort(cnt, cnt+n+1); int ans = 0; int left = n; for (int i = n; left > 0; i--) { int d = 2*cnt[i]-1; ans ++; left -= d; } cout << ans << endl; 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 32 33 34 35 36 37 38 39 40 41 42 43 44 | #include <bits/stdc++.h> #define ll long long #define fors(u, n, s) for(ll u = (s); u < (n); u++) #define foru(u, n) fors(u, n, 0) #define vec vector #define pb push_back #define f first #define s second #define ir(a, b, x) (((a) <= (x)) && ((x) <= (b))) #define pint pair<ll, ll> using namespace std; const int N = 6e5; int n; int a[N]; int cnt[N]; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> n; foru(i, n) cin >> a[i]; foru(i, n) cnt[a[i]]++; sort(cnt, cnt+n+1); int ans = 0; int left = n; for (int i = n; left > 0; i--) { int d = 2*cnt[i]-1; ans ++; left -= d; } cout << ans << endl; return 0; } |