#include <cstdio> #include <map> #include <algorithm> #include <vector> int main() { int n; scanf("%d", &n); std::map<int, int> counter; for (int i = 0; i < n; i++) { int x; scanf("%d", &x); counter[x]++; } std::vector<int> reps; for (std::map<int, int>::iterator it = counter.begin(); it != counter.end(); it++) reps.push_back(it->second); sort(reps.begin(), reps.end()); for (int k = 1; k <= n; k++) { int s = 0; int t; int i = reps.size() - 1; while (t = reps[i] / k, t > 0 && i >= 0) { s += t; i--; } printf("%d ", s * k); } 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 | #include <cstdio> #include <map> #include <algorithm> #include <vector> int main() { int n; scanf("%d", &n); std::map<int, int> counter; for (int i = 0; i < n; i++) { int x; scanf("%d", &x); counter[x]++; } std::vector<int> reps; for (std::map<int, int>::iterator it = counter.begin(); it != counter.end(); it++) reps.push_back(it->second); sort(reps.begin(), reps.end()); for (int k = 1; k <= n; k++) { int s = 0; int t; int i = reps.size() - 1; while (t = reps[i] / k, t > 0 && i >= 0) { s += t; i--; } printf("%d ", s * k); } return 0; } |