#include <iostream> #include <vector> #include <algorithm> using namespace std; void case1(){ int n; cin >> n; vector<int> data(n); for(int i = 0; i < n; ++i) cin >> data[i]; sort(data.begin(), data.end()); vector<int> num; int c = 1; int prev = data[0]; for(int i = 1; i < n; ++i){ if(data[i] == prev)++c; else{ num.push_back(c); c = 1; } prev = data[i]; } num.push_back(c); sort(num.begin(), num.end()); int s = 0; for(int i = 1; i <= n; ++i){ int ans = 0; for(int j = s; j < num.size(); ++j){ int x = (num[j] / i) * i; ans += x; if(x == 0)++s; } cout << ans << ' '; }cout<<'\n'; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); case1(); 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 49 50 51 52 53 | #include <iostream> #include <vector> #include <algorithm> using namespace std; void case1(){ int n; cin >> n; vector<int> data(n); for(int i = 0; i < n; ++i) cin >> data[i]; sort(data.begin(), data.end()); vector<int> num; int c = 1; int prev = data[0]; for(int i = 1; i < n; ++i){ if(data[i] == prev)++c; else{ num.push_back(c); c = 1; } prev = data[i]; } num.push_back(c); sort(num.begin(), num.end()); int s = 0; for(int i = 1; i <= n; ++i){ int ans = 0; for(int j = s; j < num.size(); ++j){ int x = (num[j] / i) * i; ans += x; if(x == 0)++s; } cout << ans << ' '; }cout<<'\n'; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); case1(); return 0; } |