#include<iostream> #include<algorithm> #include<vector> using namespace std; int main() { ios::sync_with_stdio(0); int N,A; vector<int> a; cin>>N; for(int i=0; i<N; ++i) { cin>>A; a.push_back(A); } sort(a.begin(),a.end()); vector<int> v; for(int i=0; i<N; ++i) { int V = 1; while(i+1 < N && a[i] == a[i+1]) { i++; V++; } v.push_back(V); } sort(v.begin(),v.end()); int sum = 0,ans = 0; for(int i=v.size(); i>=1; --i) { sum += v[i-1] + v[i-1] - 1; ans++; if(sum >= N) break; } 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 | #include<iostream> #include<algorithm> #include<vector> using namespace std; int main() { ios::sync_with_stdio(0); int N,A; vector<int> a; cin>>N; for(int i=0; i<N; ++i) { cin>>A; a.push_back(A); } sort(a.begin(),a.end()); vector<int> v; for(int i=0; i<N; ++i) { int V = 1; while(i+1 < N && a[i] == a[i+1]) { i++; V++; } v.push_back(V); } sort(v.begin(),v.end()); int sum = 0,ans = 0; for(int i=v.size(); i>=1; --i) { sum += v[i-1] + v[i-1] - 1; ans++; if(sum >= N) break; } cout<<ans<<endl; return 0; } |