1330: Five Cards
来源:互联网 发布:没有sqlserver服务 编辑:程序博客网 时间:2024/06/07 01:40
题目
Description
马克在玩一个游戏,他有5张卡片,每张卡片上会有一个数字。每个数字是一个正整数
马克可以丢弃一些卡片。他的目标是得到剩余卡片数字的最小和
允许马克丢弃两张或三张卡片(只能丢弃一次),并且丢弃的卡片的数字必须是相同的。当然,如果其中无相同数字的卡片,就不能丢弃卡片
给你5张卡片,你能找到在剩下卡片中的最小和吗?
Input
多组输入,每行输入包括5个数字t1,t2,t3,t4,和t5(1<=ti<=100),卡片上的的数字
Output
每组输出,输出剩下卡片上数字的最小和
Sample Input
7 3 7 3 20
7 9 3 1 8
10 10 10 10 10
Sample Output
26
28
20
代码块
import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner cn = new Scanner(System.in); while (cn.hasNext()) { int[] a = new int[5]; int sum = 0; for (int i = 0; i < 5; i++) { a[i] = cn.nextInt(); sum += a[i]; } int max = 0; for (int i = 0; i < 4; i++) { if (a[i] == 0) continue; int count = 0; for (int j = i + 1; j < 5; j++) { if (a[j] == 0) continue; if (a[i] == a[j]) { count++; a[j] = 0; } } if (count > 0 && count < 3) { int z = (count + 1) * a[i]; if (z > max) max = z; } else if (count >= 3) { if (max < 3 * a[i]) max = 3 * a[i]; } } System.out.println(sum - max); } }}
阅读全文
0 0
- 1330: Five Cards
- Bear and Five Cards
- A. Bear and Five Cards
- B - Bear and Five Cards
- Codeforces Round #356 (Div. 2) A - Bear and Five Cards
- Codeforces-Round-#356-(Div.-2)-Bear-and-Five-Cards
- CodeForces 680A Bear and Five Cards(取数字)
- Five
- five
- ★【16.6.9】Codeforces Round #356 (Div. 2) A. Bear and Five Cards
- Codeforces Round #356 (Div. 2)-A. Bear and Five Cards(模拟)
- code force A. Bear and Five Cards&B. Bear and Finding Criminals
- Cards
- Cards
- Cards
- Cards
- chapter five
- Five 'W'
- 记录一次Eclipse出现的奇怪的事情
- ROS实战_1.2 Pioneer 3DX ROSARIA使用教程
- POJ 2079 Triangle(旋转卡壳计算平面点集最大三角形面积)
- 学习PHP注意事项
- 奇技淫巧
- 1330: Five Cards
- sql之left join、right join、inner join的区别
- Hive数据倾斜(大表join大表)
- ccf-201604-1 折点计数
- php生成缩略图的方法
- Extjs4学习笔记(七)----combobox下拉动态树
- QT TableView 常用设置
- Node.js安装(window10需要管理员权限)
- 第一篇、maven学习之路--下载安装