9.2 美团糖果
#include
#include
#include
#include
using namespace std;
int main() {
int n;
cin >> n;
vector nums;
unordered_map map;
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
map[a]++;
}
for (auto x : map) {
nums.push_back(x.second);
}
sort(nums.begin(), nums.end());
int ans = 0;
for (int i = 0; i < nums.size(); i++) {
for (int j = i + 1; j < nums.size(); j++) {
if (nums[i] <= 0) break;
nums[i]--;
nums[j]--;
ans++;
}
if (nums[i] >= 2) ans++;
}
cout << ans;
}
//可否?
#include
#include
#include
using namespace std;
int main() {
int n;
cin >> n;
vector
unordered_map
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
map[a]++;
}
for (auto x : map) {
nums.push_back(x.second);
}
sort(nums.begin(), nums.end());
int ans = 0;
for (int i = 0; i < nums.size(); i++) {
for (int j = i + 1; j < nums.size(); j++) {
if (nums[i] <= 0) break;
nums[i]--;
nums[j]--;
ans++;
}
if (nums[i] >= 2) ans++;
}
cout << ans;
}
//可否?
全部评论
相关推荐
点赞 评论 收藏
分享
点赞 评论 收藏
分享