• Codeforces Round #356 (Div. 2)A. Bear and Five Cards(简单模拟)


    A. Bear and Five Cards
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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

    链接:http://codeforces.com/contest/680/problem/A

    这是我第一次打cf,做出了div2的A和B,感觉还不错,虽然都很水= =这题看懂了题意之后就是简单的模拟了,我写的代码重复率比较高,大多是复制粘贴的,现在也懒得改了,也许这样能看的更清楚呢!!
    只不过这么长的代码,我也是佩服我自己当时能写出来,可能是对于我来说,半夜写代码更有效率吧,,,呵呵。
    #include<bits/stdc++.h>
    using namespace std;
    
    #define Rep(i,a,b) for(int i=(a);i<=(b);i++)
    
    int mmin(int a,int b,int c)
    {
        return min(a,min(b,c));
    }
    
    int main()
    {
        int a[6]= {0};
        set<int> sei;
        for (int i=1; i<=5; i++)
        {
            cin>>a[i];
            sei.insert(a[i]);
        }
        int sum=0;
        set<int>::iterator its;
        if (sei.size()==5)
        {
            Rep(i,1,5)
            sum+=a[i];
            printf("%d
    ",sum);
            return 0;
        }
        else
        {
            if (sei.size()==1)
            {
                sum=2*a[1];
                printf("%d
    ",sum);
                return 0;
            }
            else if (sei.size()==2)
            {
                int a1=0,a2=0;
                int te[20]={0};
                int id;
                for (its=sei.begin(),id=0;its!=sei.end();id++,its++)
                {
                    te[id]=*its;
                }
                Rep(i,1,5)
                {
                    if (a[i]==te[0])
                        a1++;
                    else if (a[i]==te[1])
                        a2++;
                }
                if (a1==1||a1==4)
                {
                    printf("%d
    ",te[0]+te[1]);
                    return 0;
                }
                else if (a1==2)
                {
                    printf("%d
    ",min(te[1]*3,2*te[0]));
                    return 0;
                }
                else if (a1==3)
                {
                    printf("%d
    ",min(te[0]*3,te[1]*2));
                    return 0;
                }
            }
            else if (sei.size()==3)
            {
                int a1=0,a2=0,a3=0;
                int te[20]={0};
                int id;
                for (its=sei.begin(),id=0;its!=sei.end();id++,its++)
                {
                    te[id]=*its;
                }
                Rep(i,1,5)
                {
    
                    if (a[i]==te[0])
                        a1++;
                    else if (a[i]==te[1])
                        a2++;
                    else if (a[i]==te[2])
                        a3++;
                }
                int f1=te[0];
                int f2=te[1];
                int f3=te[2];
                if (a1==1&&a2==1)
                {
                    printf("%d
    ",f1+f2);
                    return 0;
                }
                else if (a1==1&&a2==2)
                {
                    printf("%d
    ",min(f1+2*f3,f1+2*f2));
                    return 0;
                }
                else if (a1==1&&a2==3)
                {
                    printf("%d
    ",f1+f3);
                    return 0;
                }
                else if (a1==2&&a2==1)
                {
                    printf("%d
    ",min(f2+2*f3,f2+2*f1));
                    return 0;
                }
                else if (a1==2&&a2==2)
                {
                    printf("%d
    ",min(2*f1+f3,2*f2+f3));
                    return 0;
                }
                else if (a1==3&&a2==1)
                {
                    printf("%d
    ",f2+f3);
                    return 0;
                }
            }
            else if (sei.size()==4)
            {
                int a1=0,a2=0,a3=0,a4=0;
                int te[20]={0};
                int id;
                for (its=sei.begin(),id=0;its!=sei.end();id++,its++)
                {
                    te[id]=*its;
                }
                Rep(i,1,5)
                {
                    if (a[i]==te[0])
                        a1++;
                    else if (a[i]==te[1])
                        a2++;
                    else if (a[i]==te[2])
                        a3++;
                    else if (a[i]==te[3])
                        a4++;
                }
                int f1=te[0];
                int f2=te[1];
                int f3=te[2];
                int f4=te[3];
                if (a4==2)
                {
                    printf("%d
    ",f1+f2+f3);
                    return 0;
                }
                if (a3==2)
                {
                    printf("%d
    ",f1+f2+f4);
                    return 0;
                }
                if (a2==2)
                {
                    printf("%d
    ",f1+f3+f4);
                    return 0;
                }
                if (a1==2)
                {
                    printf("%d
    ",f2+f3+f4);
                    return 0;
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    配置java环境变量
    编写Java中的第一个Java程序:HelloWorld(你好世界:问世)
    对Java的加载与执行的理解(理论比较重要)
    JDK、JRE、JVM三者之间的关系?
    Java语言的特性
    计算机编程语言发展史
    DRF解析器
    DRF分页组件
    DRF频率组件
    DRF权限组件
  • 原文地址:https://www.cnblogs.com/s1124yy/p/5575110.html
Copyright © 2020-2023  润新知