博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C - Bear and Five Cards
阅读量:5101 次
发布时间:2019-06-13

本文共 1564 字,大约阅读时间需要 5 分钟。

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 t1t2t3t4 and t5 (1 ≤ ti ≤ 100) — numbers written on cards.

 

Output

Print the minimum possible sum of numbers written on remaining cards.

 

Sample Input

Input
7 3 7 3 20
Output
26
Input
7 9 3 1 8
Output
28
Input
10 10 10 10 10
Output
20

题意:共有5张卡,可将两张或三张重复卡片扔掉,求扔掉后和的最小值。

 

排序后找到最大重复卡片和减掉即可。

 

附AC代码:

1 #include
2 #include
3 #include
4 #include
5 #include
6 using namespace std; 7 8 int a[6]; 9 int main(){10 for(int i=0;i<5;i++){11 cin>>a[i];12 }13 sort(a,a+5);14 int ans=2,Max=0,sum=0;15 for(int i=0;i<5;i++){16 if(a[i]==a[i+1]){17 if(ans<=3)//最多扔三张 18 Max=max(Max,a[i]*ans);19 ans++;20 }21 else22 ans=2;23 }24 for(int i=0;i<5;i++){25 sum+=a[i];26 }27 cout<
<

 

转载于:https://www.cnblogs.com/Kiven5197/p/5659197.html

你可能感兴趣的文章
App右上角数字
查看>>
小算法
查看>>
新作《ASP.NET MVC 5框架揭秘》正式出版
查看>>
WPF中实现多选ComboBox控件
查看>>
读构建之法第四章第十七章有感
查看>>
Windows Phone开发(4):框架和页 转:http://blog.csdn.net/tcjiaan/article/details/7263146
查看>>
python asyncio 异步实现mongodb数据转xls文件
查看>>
TestNG入门
查看>>
【ul开发攻略】HTML5/CSS3菜单代码 阴影+发光+圆角
查看>>
IOS-图片操作集合
查看>>
IO—》Properties类&序列化流与反序列化流
查看>>
Codeforces 719B Anatoly and Cockroaches
查看>>
ActiveMQ与spring整合
查看>>
EOS生产区块:解析插件producer_plugin
查看>>
格式化输出数字和时间
查看>>
关于TFS2010使用常见问题
查看>>
URL编码与解码
查看>>
Eclipse 安装SVN插件
查看>>
阿里云服务器CentOS6.9安装Mysql
查看>>
剑指offer系列6:数值的整数次方
查看>>