#include<bits/stdc++.h>
#define MAXN 500003
using namespace std;
int T[MAXN];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int x;
for(int i = 1 ; i <= n ; ++ i){
cin >> x;
++ T[x];
}
priority_queue<int> Q;
for(int i = 1 ; i <= n ; ++ i){
if(T[i] != 0){
Q.push(T[i]);
}
}
int L = 0;
int W = 0;
while(!Q.empty()){
int t = Q.top();
Q.pop();
W += (2 * t - 1);
++ L;
if(W >= n) break;
}
cout << L;
}
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 | #include<bits/stdc++.h> #define MAXN 500003 using namespace std; int T[MAXN]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int x; for(int i = 1 ; i <= n ; ++ i){ cin >> x; ++ T[x]; } priority_queue<int> Q; for(int i = 1 ; i <= n ; ++ i){ if(T[i] != 0){ Q.push(T[i]); } } int L = 0; int W = 0; while(!Q.empty()){ int t = Q.top(); Q.pop(); W += (2 * t - 1); ++ L; if(W >= n) break; } cout << L; } |
English