#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie();cout.tie();
map<int,int> M;
vector<int> V;
int n,x,t;
cin>>n;
t=n;
while(t--)
{
cin>>x;
M[x]++;
}
for(auto &i: M)
{
V.push_back(-i.second);
}
sort(V.begin(),V.end());
int w=1, s=0;
while(-V[s]*2-1<n)
{
n-=(-V[s]*2-1);
++s;
++w;
//cout<<w<<" - "<<n<<endl;
}
cout<<w<<endl;
}
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 <iostream> #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie();cout.tie(); map<int,int> M; vector<int> V; int n,x,t; cin>>n; t=n; while(t--) { cin>>x; M[x]++; } for(auto &i: M) { V.push_back(-i.second); } sort(V.begin(),V.end()); int w=1, s=0; while(-V[s]*2-1<n) { n-=(-V[s]*2-1); ++s; ++w; //cout<<w<<" - "<<n<<endl; } cout<<w<<endl; } |
English