#include <bits/stdc++.h>
#include <cmath>
#include <stdlib.h>
using namespace std;
const long long mod = 1000000007;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> vec;
vector<int> his(n + 1, 0);
for (int i = 0; i < n; i++)
{
int a;
cin >> a;
vec.push_back(a);
}
// vec.push_back(-INT32_MAX);
// int last = vec[0];
// int cnt = 0;
for (auto &&a : vec)
{
his[a]++;
// if (a != last)
// {
// his.push_back(cnt);
// cnt = 0;
// }
// last = a;
// cnt++;
}
sort(his.begin(), his.end());
// sort(vec.begin(), vec.end());
// reverse(his.begin(),his.end());
for (int i = 0; i < his.size(); i++)
{
for (int j = 0; j <= i; j++)
{
if (his[j] <= his[i] / 2)
{
// his[i]-=his[j];
his[j] = 0;
}
}
}
int cnt = 0;
for (auto &&a : his)
{
if (a > 0)
{
cnt++;
}
}
// for(auto&& a: his){
// cout<<a<<' ';
// }
cout << cnt << '\n';
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #include <bits/stdc++.h> #include <cmath> #include <stdlib.h> using namespace std; const long long mod = 1000000007; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> vec; vector<int> his(n + 1, 0); for (int i = 0; i < n; i++) { int a; cin >> a; vec.push_back(a); } // vec.push_back(-INT32_MAX); // int last = vec[0]; // int cnt = 0; for (auto &&a : vec) { his[a]++; // if (a != last) // { // his.push_back(cnt); // cnt = 0; // } // last = a; // cnt++; } sort(his.begin(), his.end()); // sort(vec.begin(), vec.end()); // reverse(his.begin(),his.end()); for (int i = 0; i < his.size(); i++) { for (int j = 0; j <= i; j++) { if (his[j] <= his[i] / 2) { // his[i]-=his[j]; his[j] = 0; } } } int cnt = 0; for (auto &&a : his) { if (a > 0) { cnt++; } } // for(auto&& a: his){ // cout<<a<<' '; // } cout << cnt << '\n'; return 0; } |
English