#include <bits/stdc++.h>
using namespace std;
bool test(int a,int b)
{
return a>b;
}
unordered_map<int,int> ma;
vector<int> acc;
vector<int> tab;
int main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
int N;cin>>N;
for(int i=0;i<N;i++)
{
int x;cin>>x;
if(ma[x]==0)
{
acc.push_back(x);
}
ma[x]++;
}
for(int i=0;i<acc.size();i++)
{
tab.push_back(ma[acc[i]]);
}
sort(tab.begin(),tab.end(),test);
int b=0;
int sum=0;
while(sum<N)
{
sum+=2*tab[b] -1 ;
if(sum<N) b++;
}
cout<<b+1;
}
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 | #include <bits/stdc++.h> using namespace std; bool test(int a,int b) { return a>b; } unordered_map<int,int> ma; vector<int> acc; vector<int> tab; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int N;cin>>N; for(int i=0;i<N;i++) { int x;cin>>x; if(ma[x]==0) { acc.push_back(x); } ma[x]++; } for(int i=0;i<acc.size();i++) { tab.push_back(ma[acc[i]]); } sort(tab.begin(),tab.end(),test); int b=0; int sum=0; while(sum<N) { sum+=2*tab[b] -1 ; if(sum<N) b++; } cout<<b+1; } |
English