#include <bits/stdc++.h> using namespace std; const int roz = 500007; int tab[roz]; pair<int, int> wla[roz]; int ile[roz]; int main(){ int n; cin>>n; for(int i = 0; i<n; i++){ cin>>tab[i]; ile[tab[i]]++; } for(int i = 0; i<n; i++){ wla[i] = {ile[tab[i]]*-1, tab[i]}; } sort(wla, wla+n); int pocz = 0, wyn = 0, kon = n, ter; while(pocz<kon){ wyn++; ter = wla[pocz].second; while(pocz<kon && ter == wla[pocz].second){ pocz++; } kon -= ((wla[pocz-1].first*-1)-1); } cout<<wyn; }
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 | #include <bits/stdc++.h> using namespace std; const int roz = 500007; int tab[roz]; pair<int, int> wla[roz]; int ile[roz]; int main(){ int n; cin>>n; for(int i = 0; i<n; i++){ cin>>tab[i]; ile[tab[i]]++; } for(int i = 0; i<n; i++){ wla[i] = {ile[tab[i]]*-1, tab[i]}; } sort(wla, wla+n); int pocz = 0, wyn = 0, kon = n, ter; while(pocz<kon){ wyn++; ter = wla[pocz].second; while(pocz<kon && ter == wla[pocz].second){ pocz++; } kon -= ((wla[pocz-1].first*-1)-1); } cout<<wyn; } |