zoukankan      html  css  js  c++  java
  • Codeforces Round #356 (Div. 2)-A

    A. Bear and Five Cards
    题目链接:http://codeforces.com/contest/680/problem/A

    A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.

    Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.

    He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number.

    Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards?

    Input

    The only line of the input contains five integers t1, t2, t3, t4 and t5 (1 ≤ ti ≤ 100) — numbers written on cards.

    Output

    Print the minimum possible sum of numbers written on remaining cards.

    Examples
    input
    7 3 7 3 20
    output
    26
    input
    7 9 3 1 8
    output
    28
    input
    10 10 10 10 10
    output
    20
    Note

    In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.

    • Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40.
    • Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26.
    • Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34.

    You are asked to minimize the sum so the answer is 26.

    In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28.

    In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20.

     题意:有5张卡,每张卡有一个数字。现在可以丢弃一些卡,丢弃的卡要满足:存在2-3张数字一样的卡。 问最小的数字总和是多少?

     思路:只要5张卡,暴力就好,注意要存在2-3张数字一样的卡才能丢弃,而且最多丢弃1次,数量最多是3张

    #include<iostream>
    #include<stdio.h>
    #include<cstring>
    #include<string>
    #include<algorithm>
    using namespace std; 
    const int MAXN=5+5;
    typedef long long int LL;
    #define INF 0x3f3f3f3f
    int T[MAXN],tot[105];
    int main()
    {
        while(~scanf("%d%d%d%d%d",&T[0],&T[1],&T[2],&T[3],&T[4])){
            int sum=0;
            memset(tot,0,sizeof(tot));
            for(int i=0;i<5;i++){
                sum+=T[i];
                tot[T[i]]++;
            }
            int maxval=0;
            for(int i=1;i<=100;i++){
                maxval=max(maxval,i*min(3,(tot[i]>=2?tot[i]:0)));
            }
            printf("%d
    ",sum-maxval);
        }
        return 0;
    }
  • 相关阅读:
    天大复试机试练习_003
    C++随手记--字符串转数字
    C++标准库STL 之 我觉得应该有的方法——split
    apt-get 详解&&配置阿里源
    Nginx 图文详解
    MySQL数据库管理常用命令小结
    oracle数据库备份
    SqlServer数据库备份还原步骤
    mysql数据备份与恢复
    Tomcat架构
  • 原文地址:https://www.cnblogs.com/kirito520/p/5572306.html
Copyright © 2011-2022 走看看