C - Bear and Five Cards
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
Input7 3 7 3 20Output26Input7 9 3 1 8Output28Input10 10 10 10 10Output20
题意:共有5张卡,可将两张或三张重复卡片扔掉,求扔掉后和的最小值。
排序后找到最大重复卡片和减掉即可。
附AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std; int a[];
int main(){
for(int i=;i<;i++){
cin>>a[i];
}
sort(a,a+);
int ans=,Max=,sum=;
for(int i=;i<;i++){
if(a[i]==a[i+]){
if(ans<=)//最多扔三张
Max=max(Max,a[i]*ans);
ans++;
}
else
ans=;
}
for(int i=;i<;i++){
sum+=a[i];
}
cout<<sum-Max<<endl;
return ;
}
C - Bear and Five Cards的更多相关文章
- 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 stand ...
- codeforces 680A A. Bear and Five Cards(水题)
题目链接: A. Bear and Five Cards //#include <bits/stdc++.h> #include <vector> #include <i ...
- 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 be ...
- [ An Ac a Day ^_^ ] CodeForces 680A Bear and Five Cards
这两天回家了 家里电脑太卡 调试不方便 就只能写写水题了…… #include<stdio.h> #include<iostream> #include<algorith ...
- A- Bear and Five Cards(codeforces ROUND356 DIV2)
A. Bear and Five Cards time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #356 (Div. 2)-A
A. Bear and Five Cards 题目链接:http://codeforces.com/contest/680/problem/A A little bear Limak plays a ...
- Codeforces Round #356 (Div. 2)
A. Bear and Five Cards time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- BZOJ 1004 【HNOI2008】 Cards
题目链接:Cards 听说这道题是染色问题的入门题,于是就去学了一下\(Bunside\)引理和\(P\acute{o}lya\)定理(其实还是没有懂),回来写这道题. 由于题目中保证"任意 ...
- Codeforces CF#628 Education 8 F. Bear and Fair Set
F. Bear and Fair Set time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
随机推荐
- C#数据类型与数据库字段类型对应
数据库 C#程序 int int32 text string bigint int64 binary System.Byte[] bit Boolean char string datetime Sy ...
- Canvas学习笔记——动画中的三角学
示例1,跟随鼠标的键头: 需要掌握一个重要的公式,这个方法返回从 x 轴到点 (x,y) 之间的角度 Math.atan2(dy,dx); 关键代码: function Arrow() { thi ...
- Android 向右滑动销毁(finish)Activity, 随着手势的滑动而滑动的效果
http://blog.csdn.net/xiaanming/article/details/20934541
- HUD 2031: 进制转换
进制转换 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- 在html中显示Flash的代码
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://down ...
- Presenting view controllers on detached view controllers is discouraged
本文转载至 http://www.xuebuyuan.com/2117943.html Presenting view controllers on detached view controllers ...
- VLC RTP Over TCP
在RTSP协议请求数据时,让VLC以TCP的方式获取服务器发来的RTP数据 不为别的,下次回复直接用博客链接就能回复大家了! 操作:工具 -> 首选项 然后: 搞定! ------------- ...
- java基础知识查漏 四
1.JAVA多线程实现方式 (1)继承Thread类,并重写run()方法 (2)实现Runnable接口,,实现run()方法 (3)使用ExecutorService.Callable.Futur ...
- java关于数组之间的相互赋值
java中数组是被当作对象看待,假设a,b为两个已经初始化的数组,那么语句a=b就表示把b数组对象的引用赋值给a,那么a和b就指向了同一个数组,无论用哪个来操作都影响其指向的数组.原来a指向的数组现在 ...
- Theseven relationsarein threecategories:equivalent, congruent, andsimilar.
http://www.math.pitt.edu/~xfc/math2370/chap5.pdf