#include <iostream> #include <map> #include <algorithm> #include <vector> int main(){ int n; std::cin>>n; std::map<int, int> m; for(int i=0; i<n; i++){ int a; std::cin>>a; m[a]++; } std::vector<int> v; for(auto it = m.begin(); it!=m.end(); it++){ v.push_back(it->second); } std::sort(v.begin(), v.end()); std::vector<int> result(n+1, 0); for (int i=0; i<v.size(); i++){ for (int j=1; j<=n; j++){ // /std::cout<<v[i]<<" "<<j<<std::endl; if (v[i]/j == 0){ break; } result[j] += v[i] - v[i]%j; } } for (int i=1; i<=n; i++){ std::cout<<result[i]<<" "; } }
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 | #include <iostream> #include <map> #include <algorithm> #include <vector> int main(){ int n; std::cin>>n; std::map<int, int> m; for(int i=0; i<n; i++){ int a; std::cin>>a; m[a]++; } std::vector<int> v; for(auto it = m.begin(); it!=m.end(); it++){ v.push_back(it->second); } std::sort(v.begin(), v.end()); std::vector<int> result(n+1, 0); for (int i=0; i<v.size(); i++){ for (int j=1; j<=n; j++){ // /std::cout<<v[i]<<" "<<j<<std::endl; if (v[i]/j == 0){ break; } result[j] += v[i] - v[i]%j; } } for (int i=1; i<=n; i++){ std::cout<<result[i]<<" "; } } |