#include <bits/stdc++.h> using namespace std; int arr[1000000]; int main(){ int n,a; int m; int sum; map<int,int> M; cin>>n; for(int i=0;i<n;++i){ cin>>a; M[a]++; } int it = 0; for(auto i = M.begin(); i != M.end(); ++i){ arr[it] = -i->second; ++it; } m=M.size(); sort(arr,arr+m); for(int i = 0;i<m;++i){ arr[i] = -arr[i]; } arr[m] = 0; for(int i =1;i<=n;++i){ sum=0; for(int j = 0; arr[j]/i > 0; ++j){ sum += (arr[j]/i) * i; } cout<<sum<<' '; } 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 | #include <bits/stdc++.h> using namespace std; int arr[1000000]; int main(){ int n,a; int m; int sum; map<int,int> M; cin>>n; for(int i=0;i<n;++i){ cin>>a; M[a]++; } int it = 0; for(auto i = M.begin(); i != M.end(); ++i){ arr[it] = -i->second; ++it; } m=M.size(); sort(arr,arr+m); for(int i = 0;i<m;++i){ arr[i] = -arr[i]; } arr[m] = 0; for(int i =1;i<=n;++i){ sum=0; for(int j = 0; arr[j]/i > 0; ++j){ sum += (arr[j]/i) * i; } cout<<sum<<' '; } return 0; } |