#include <iostream> #include <algorithm> #include <vector> #include <map> using namespace std; int main() { int n; map<int,int> city_to_num; int res = 0; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; city_to_num[x]++; } vector<int> ans(n + 1); for (auto it: city_to_num) { int num = it.second; for(int i = 1; i <= num; i++) { ans[i] += (num / i) * i; } } for (int i = 1; i <=n; i++) { cout << ans[i] << " "; } 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 | #include <iostream> #include <algorithm> #include <vector> #include <map> using namespace std; int main() { int n; map<int,int> city_to_num; int res = 0; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; city_to_num[x]++; } vector<int> ans(n + 1); for (auto it: city_to_num) { int num = it.second; for(int i = 1; i <= num; i++) { ans[i] += (num / i) * i; } } for (int i = 1; i <=n; i++) { cout << ans[i] << " "; } return 0; } |