AtCoder Beginner Contest 053 D - Card Eater (thinking)

Problem Statement

 

Snuke has decided to play a game using cards. He has a deck consisting of NN cards. On the ii -th card from the top, an integer AiAi is written.

He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, NN is odd, which guarantees that at least one card can be kept.

Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.

Constraints

 

  • 3N1053≦N≦105
  • NN is odd.
  • 1Ai1051≦Ai≦105
  • AiAi is an integer.

Input

 

The input is given from Standard Input in the following format:

N N 
A 1 the A1  A 2 the A2  A 3 the A3 ... A N the AN

Output

 

Print the answer.

Sample Input 1

 

5
1 2 1 3 7

Sample Output 1

 

3

One optimal solution is to perform the operation once, taking out two cards with 11 and one card with 22 . One card with 11 and another with 22 will be eaten, and the remaining card with 11 will be returned to deck. Then, the values written on the remaining cards in the deck will be pairwise distinct: 11 , 33 and 77 .

Sample Input 2

 

15
1 3 5 2 1 3 2 8 8 6 2 6 11 1 1

Sample Output 2

 

7

Sponsor

Very good attendance problems. Every time a smoke equivalent to smoking two three back without replacement, since the requirements of the final remaining cards at most, can be considered greedy, extract more out of each priority duplicate cards, if these extra card is repeated even number, then smoked them all; if it is an odd number is more than a draw to make up the numbers, which can meet most of the rest.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n,a[100005]={0};
int main()
{
    cin>>n;
    int i;
    for(i=1;i<=n;i++)
    {
        int temp;
        scanf("%d",&temp);
        a[temp]++;
    }
    int sum=0,res=0;
    for(i=1;i<=100005;i++)
    {
        sum+=a[i];
        if(a[i]>1)res+=a[i]-1;
    }
    if(res%2==0)
    {
        cout<<sum-res;
    }
    else
    {
        cout<<sum-res-1;
    }
    return 0;
 } 

 

Guess you like

Origin www.cnblogs.com/lipoicyclic/p/12590439.html