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
    《一级架构师实践指南》阅读笔记
    需求概述开发进度14
    需求概述开发进度13
    需求概述开发进度12
    需求概述开发进度11
    需求概述开发进度10
    爬虫的requests库和BeautifulSoup4的学习
    模拟体育竞技分析
    python文件格式转换
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5572045.html
Copyright © 2011-2022 走看看