abc053d <简单贪心>
https://atcoder.jp/contests/abc053/tasks/arc068_b
// https://atcoder.jp/contests/abc053/tasks/arc068_b
// 当某个数字个数n>=3, 可直接拿出3个进行操作, 每次减少两个 ;
// 这样做会使得每个数字的个数都变为 1 or 2 ;
// 统计个数为 1,2 的数字的个数,
// 若个数为2的数字为奇数, 则需要消耗一个个数为1的数字; 为偶数, 则ans = cnts[1] + cnts[2] ;
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
void solv()
{
int n, a;
cin >> n;
map<int, int> mp;
for (int i = 0; i < n; i ++)
{
cin >> a;
mp[a] ++;
}
int cnts[3] = {0};
for (auto const &it: mp)
{
cnts[(it.second - 1) % 2 + 1] ++;
}
int ans = cnts[1] + cnts[2]; // 若cnts[2]为偶数
if (cnts[2] % 2 == 1) ans --;
cout << ans << endl;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int T = 1;
// cin >> T;
while (T --)
{
solv();
}
return 0;
}
本文来自博客园,作者:O2iginal,转载请注明原文链接:https://www.cnblogs.com/o2iginal/p/17490686.html