[Arc068D/At2299] Card Eater

[Arc068D/At2299]
有一堆牌,每张牌上有一个数字。 每次可以取出其中 (3) 张,丢掉数字最大的和数字最小的牌,把中间那张再放回牌堆。 要求最后所有剩余牌上的数字互不相同,求最多能剩几张牌。

设重复数为“多余”的牌的数量

如果重复数是偶数,容易猜得一定存在方案使得可以恰好去掉所有重复的牌

如果重复数是奇数,我们要想去掉重复,就必须要多去掉一张牌

我居然手滑血了一发

#include <bits/stdc++.h>
using namespace std;

int a[1000005],n,t;

int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&t), a[t]++;
    int cnt = 0;
    for(int i=1;i<=100000;i++) if(a[i]>1) cnt+=a[i]-1;
    if(cnt&1) n-=cnt+1;
    else n-=cnt;
    cout<<n<<endl;
}
原文地址:https://www.cnblogs.com/mollnn/p/12268063.html