#include<bits/stdc++.h> using namespace std; const int N = 5e5 + 5; int n = 0, c[N] = {}, ans = 0; int main(){ scanf("%d", &n); for(int i = 0, x = 0 ; i < n ; i ++){ scanf("%d", &x), x --; c[x] ++; } sort(c, c + n), reverse(c, c + n); for(int l = 0, r = n - 1 ; l <= r ; ans ++){ int x = c[l ++] - 1; while(r >= l && x > 0){ if(x < c[r]) c[r] -= x, x = 0; else x -= c[r --]; } } printf("%d", ans); 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 | #include<bits/stdc++.h> using namespace std; const int N = 5e5 + 5; int n = 0, c[N] = {}, ans = 0; int main(){ scanf("%d", &n); for(int i = 0, x = 0 ; i < n ; i ++){ scanf("%d", &x), x --; c[x] ++; } sort(c, c + n), reverse(c, c + n); for(int l = 0, r = n - 1 ; l <= r ; ans ++){ int x = c[l ++] - 1; while(r >= l && x > 0){ if(x < c[r]) c[r] -= x, x = 0; else x -= c[r --]; } } printf("%d", ans); return 0; } |