#include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { int n; cin >> n; int city[n]; vector <int> counts; for(int i = 0; i < n; i++) { cin >> city[i]; } sort(city, city+n); int x = 0, y; while(x < n) { y = 1; while(x+y <= n && city[x+y] == city[x]) { y++; } x += y; counts.push_back(y); } x = counts.size(); sort(counts.begin(), counts.end()); int result; for(int k = 1; k <= n; k++) { result = 0; for(int i = x - 1; i >= 0; i--) { if(counts[i] < k) {break;} result += counts[i]/k; } cout << k*result << " "; } 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 | #include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { int n; cin >> n; int city[n]; vector <int> counts; for(int i = 0; i < n; i++) { cin >> city[i]; } sort(city, city+n); int x = 0, y; while(x < n) { y = 1; while(x+y <= n && city[x+y] == city[x]) { y++; } x += y; counts.push_back(y); } x = counts.size(); sort(counts.begin(), counts.end()); int result; for(int k = 1; k <= n; k++) { result = 0; for(int i = x - 1; i >= 0; i--) { if(counts[i] < k) {break;} result += counts[i]/k; } cout << k*result << " "; } return 0; } |