• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
ACM s1124yy
守りたいものが 強くさせること
博客园    首页    新随笔    联系   管理     

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\n",sum);
        return 0;
    }
    else
    {
        if (sei.size()==1)
        {
            sum=2*a[1];
            printf("%d\n",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\n",te[0]+te[1]);
                return 0;
            }
            else if (a1==2)
            {
                printf("%d\n",min(te[1]*3,2*te[0]));
                return 0;
            }
            else if (a1==3)
            {
                printf("%d\n",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\n",f1+f2);
                return 0;
            }
            else if (a1==1&&a2==2)
            {
                printf("%d\n",min(f1+2*f3,f1+2*f2));
                return 0;
            }
            else if (a1==1&&a2==3)
            {
                printf("%d\n",f1+f3);
                return 0;
            }
            else if (a1==2&&a2==1)
            {
                printf("%d\n",min(f2+2*f3,f2+2*f1));
                return 0;
            }
            else if (a1==2&&a2==2)
            {
                printf("%d\n",min(2*f1+f3,2*f2+f3));
                return 0;
            }
            else if (a1==3&&a2==1)
            {
                printf("%d\n",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\n",f1+f2+f3);
                return 0;
            }
            if (a3==2)
            {
                printf("%d\n",f1+f2+f4);
                return 0;
            }
            if (a2==2)
            {
                printf("%d\n",f1+f3+f4);
                return 0;
            }
            if (a1==2)
            {
                printf("%d\n",f2+f3+f4);
                return 0;
            }
        }
    }
    return 0;
}
posted @ 2016-06-11 11:57  s1124yy  阅读(241)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3