CodeForces 680A Bear and Five Cards(取数字)
2016-08-15 16:20
603 查看
http://codeforces.com/problemset/problem/680/A
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
output
input
output
input
output
Note
In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20.
Limak can do one of the following.
Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40.
Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26.
Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34.
You are asked to minimize the sum so the answer is 26.
In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is7 + 9 + 1 + 3 + 8 = 28.
In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is10 + 10 = 20.
题意:
给定五个数字,最多取出两个相同的数字,取出之后找出最小的和。
Code:
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
Note
In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20.
Limak can do one of the following.
Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40.
Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26.
Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34.
You are asked to minimize the sum so the answer is 26.
In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is7 + 9 + 1 + 3 + 8 = 28.
In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is10 + 10 = 20.
题意:
给定五个数字,最多取出两个相同的数字,取出之后找出最小的和。
Code:
#include<stdio.h> #include<string.h> const int MYDD=1103; int main() { int num[MYDD];// num[j] 数字 j 的个数是num[j] int sum=0; memset(num,0,sizeof(num)); for(int j=0; j<5; j++) { int n; scanf("%d",&n); num ++; sum+=n; } int max=0; for(int j=1; j<=100; j++) { int temp=0; if(num[j]==2) temp=j*2; if(num[j]>2) temp=j*3; if(temp>max) max=temp; } int ans=sum-max; printf("%d\n",ans); return 0; } /*By: Shyazhut */
相关文章推荐
- js作用域
- 浅谈Java中的hashcode方法
- 月光微博客
- ASP.NET中MD5和SHA1加密的几种方法
- 【JAVA语言程序设计基础篇】--事件驱动程序设计--定义监听器的另一种方式
- kafka入门:简介、使用场景、设计原理、主要配置及集群搭建(转)
- dbutils操作数据库
- 读源码---thunkify
- hover一个组件,另一个组件css效果
- poj 1336 The K-League (网络流)
- 选项卡(JTabbedPane)的定义
- linux grep命令
- Oracle自动备份脚本(网上找到的资料)
- Zhu and 772002---hdu5833(高斯消元解求异或方程组)
- 移动端IM系统的协议选型:UDP还是TCP?
- DELPHI存取JPEG、BMP图像到数据库完整解决方案
- 8月11日 集训测试
- Android进程间通讯之AIDL
- handler.post方法的终极最直观的理解与解释
- 推荐一些css reset