zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest 053 D

    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:

    NN
    
    
    A1A1
    
     A2A2
    
     A3A3
    
     ... ANAN
    
    
    

    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

    挺不错的签到题。每次抽三张放回一张相当于抽两张不放回,既然要求最终剩余的卡片最多,可以贪心地考虑,每次优先抽取多出来的重复的卡片,如果这些多出来的重复卡片是偶数张,那么把它们全抽完;如果是奇数张则多抽一张来凑数,这样能满足剩下的最多。

    #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;
     } 
  • 相关阅读:
    HDFS snapshot操作实战
    不是技术牛人,如何拿到国内IT巨头的Offer(转载)
    HBase的RowKey设计原则
    hbase shell 基本命令总结
    13_Python数据类型字符串加强_Python编程之路
    监督学习与无监督学习的区别_机器学习
    12_Python的(匿名函数)Lambda表达式_Python编程之路
    Python数据挖掘_Python2模块Spynner的安装(安装失败)
    06_Linux目录文件操作命令3查找命令_我的Linux之路
    python数据挖掘_Json结构分析
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/12590439.html
Copyright © 2011-2022 走看看