zoukankan      html  css  js  c++  java
  • Codeforces Round #356 (Div. 2) A. Bear and Five Cards 水题

    A. Bear and Five Cards

    题目连接:

    http://www.codeforces.com/contest/680/problem/A

    Description

    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.

    Sample Input

    7 3 7 3 20

    Sample Output

    7 3 7 3 20

    Hint

    题意

    你现在有五张牌,你可以删去相同的两张,或者三张,问你删去之后,这五张牌最小的和是多少?

    题解:

    模拟一遍就好了,模拟删除哪几张就行了……

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    int n,x,sum,ans;
    map<int,int>H;
    int main()
    {
        n=5;
        for(int i=0;i<n;i++){
            scanf("%d",&x);
            H[x]++;
            sum+=x;
        }
        ans=sum;
        for(auto v:H){
            if(v.second>2)
                ans=min(ans,sum-3*v.first);
            if(v.second>1)
                ans=min(ans,sum-2*v.first);
        }
        cout<<ans<<endl;
    }
  • 相关阅读:
    01:求平均年龄
    09:与圆相关的计算
    08:温度表达转化
    07:计算多项式的值
    06:甲流疫情死亡率
    05:计算分数的浮点数值
    04:带余除法
    03:计算(a+b)/c的值
    02:计算(a+b)*c的值
    01:A+B问题
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5572045.html
Copyright © 2011-2022 走看看