2 seconds
256 megabytes
standard input
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?
The only line of the input contains five integers t1, t2, t3, t4 and t5 (1 ≤ ti ≤ 100) — numbers written on cards.
Print the minimum possible sum of numbers written on remaining cards.
7 3 7 3 20
26
7 9 3 1 8
28
10 10 10 10 10
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[]= {};
set<int> sei;
for (int i=; i<=; i++)
{
cin>>a[i];
sei.insert(a[i]);
}
int sum=;
set<int>::iterator its;
if (sei.size()==)
{
Rep(i,,)
sum+=a[i];
printf("%d\n",sum);
return ;
}
else
{
if (sei.size()==)
{
sum=*a[];
printf("%d\n",sum);
return ;
}
else if (sei.size()==)
{
int a1=,a2=;
int te[]={};
int id;
for (its=sei.begin(),id=;its!=sei.end();id++,its++)
{
te[id]=*its;
}
Rep(i,,)
{
if (a[i]==te[])
a1++;
else if (a[i]==te[])
a2++;
}
if (a1==||a1==)
{
printf("%d\n",te[]+te[]);
return ;
}
else if (a1==)
{
printf("%d\n",min(te[]*,*te[]));
return ;
}
else if (a1==)
{
printf("%d\n",min(te[]*,te[]*));
return ;
}
}
else if (sei.size()==)
{
int a1=,a2=,a3=;
int te[]={};
int id;
for (its=sei.begin(),id=;its!=sei.end();id++,its++)
{
te[id]=*its;
}
Rep(i,,)
{ if (a[i]==te[])
a1++;
else if (a[i]==te[])
a2++;
else if (a[i]==te[])
a3++;
}
int f1=te[];
int f2=te[];
int f3=te[];
if (a1==&&a2==)
{
printf("%d\n",f1+f2);
return ;
}
else if (a1==&&a2==)
{
printf("%d\n",min(f1+*f3,f1+*f2));
return ;
}
else if (a1==&&a2==)
{
printf("%d\n",f1+f3);
return ;
}
else if (a1==&&a2==)
{
printf("%d\n",min(f2+*f3,f2+*f1));
return ;
}
else if (a1==&&a2==)
{
printf("%d\n",min(*f1+f3,*f2+f3));
return ;
}
else if (a1==&&a2==)
{
printf("%d\n",f2+f3);
return ;
}
}
else if (sei.size()==)
{
int a1=,a2=,a3=,a4=;
int te[]={};
int id;
for (its=sei.begin(),id=;its!=sei.end();id++,its++)
{
te[id]=*its;
}
Rep(i,,)
{
if (a[i]==te[])
a1++;
else if (a[i]==te[])
a2++;
else if (a[i]==te[])
a3++;
else if (a[i]==te[])
a4++;
}
int f1=te[];
int f2=te[];
int f3=te[];
int f4=te[];
if (a4==)
{
printf("%d\n",f1+f2+f3);
return ;
}
if (a3==)
{
printf("%d\n",f1+f2+f4);
return ;
}
if (a2==)
{
printf("%d\n",f1+f3+f4);
return ;
}
if (a1==)
{
printf("%d\n",f2+f3+f4);
return ;
}
}
}
return ;
}