#include <iostream> #include <vector> #include <algorithm> #include <numeric> #include <string> #include <map> using namespace std; void calc(vector<int> & c_s, int i, vector<int> & c) { int k =0; int sum = 0; int all = c[0] + c_s[0]; while(k<c_s.size()) { sum+=((c_s[k])%i); if( i> c_s[k]){ sum+=c[k]; break;} ++k; } cout << all-sum <<" "; } int main() { ios_base::sync_with_stdio(false); int n; cin>>n; vector<int> st(n,0); for(int i=0;i<n;++i) cin>>st[i]; map<int,int> st_n; for(const auto& s:st) { if(st_n.find(s)!=st_n.end()) ++st_n[s]; else st_n[s]=1; } vector<int> c_s; for(const auto& s:st_n) c_s.push_back(s.second); sort(c_s.begin(), c_s.end(), greater<int>()); int m = c_s.size(); vector<int> sum(m, 0); for(int i =0; i<m-1; ++i){ sum[m-i-2] = sum[m-i-1]+ c_s[m-i-1];} for(int i=1;i<=n;++i) calc(c_s, i, 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 39 40 41 42 43 44 45 46 47 48 | #include <iostream> #include <vector> #include <algorithm> #include <numeric> #include <string> #include <map> using namespace std; void calc(vector<int> & c_s, int i, vector<int> & c) { int k =0; int sum = 0; int all = c[0] + c_s[0]; while(k<c_s.size()) { sum+=((c_s[k])%i); if( i> c_s[k]){ sum+=c[k]; break;} ++k; } cout << all-sum <<" "; } int main() { ios_base::sync_with_stdio(false); int n; cin>>n; vector<int> st(n,0); for(int i=0;i<n;++i) cin>>st[i]; map<int,int> st_n; for(const auto& s:st) { if(st_n.find(s)!=st_n.end()) ++st_n[s]; else st_n[s]=1; } vector<int> c_s; for(const auto& s:st_n) c_s.push_back(s.second); sort(c_s.begin(), c_s.end(), greater<int>()); int m = c_s.size(); vector<int> sum(m, 0); for(int i =0; i<m-1; ++i){ sum[m-i-2] = sum[m-i-1]+ c_s[m-i-1];} for(int i=1;i<=n;++i) calc(c_s, i, sum); return 0; } |