#include <bits/stdc++.h> using namespace std; struct cp { bool operator()(const pair<int,int>x, const pair<int,int>y) const { if(x.second!=y.second) return x.second>y.second; else return x.first>=y.first; } }; int main() { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(NULL); int x,pom,pp; cin >> x; set<pair<int,int>,cp> set1; set<pair<int,int>,cp>::iterator it; int tab[x+1]={0}; for (int i=0; i<x; i++) { cin >> pom; tab[pom]++; } for (int i=0; i<x; i++) if (tab[i]!=0) set1.insert({i,tab[i]}); int ile=0; while (set1.size()) { ile++; pom=(*set1.begin()).second; set1.erase(set1.begin()); pp=0; while (pp<pom&&set1.size()) { it=set1.end(); it--; pp+=(*it).second; if (pp>=pom) break; set1.erase(it); } } cout << ile; 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 | #include <bits/stdc++.h> using namespace std; struct cp { bool operator()(const pair<int,int>x, const pair<int,int>y) const { if(x.second!=y.second) return x.second>y.second; else return x.first>=y.first; } }; int main() { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(NULL); int x,pom,pp; cin >> x; set<pair<int,int>,cp> set1; set<pair<int,int>,cp>::iterator it; int tab[x+1]={0}; for (int i=0; i<x; i++) { cin >> pom; tab[pom]++; } for (int i=0; i<x; i++) if (tab[i]!=0) set1.insert({i,tab[i]}); int ile=0; while (set1.size()) { ile++; pom=(*set1.begin()).second; set1.erase(set1.begin()); pp=0; while (pp<pom&&set1.size()) { it=set1.end(); it--; pp+=(*it).second; if (pp>=pom) break; set1.erase(it); } } cout << ile; return 0; } |