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
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 is 7 + 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 is 10 + 10 = 20.
___________________
题意: 给你5个数,只能删除其中2个或3个相同的数,输出最小的和 。
这道题其实只要统计(数字范围小于100,可桶排) 每个数字出现的次数,然后对出现二次以上的数字枚举减去他们的结果,然后输出最小的那个答案就可以了。
我蠢就蠢在 老是想暴力 枚举,并没有换一个思路换一个思想方面考虑问题,所以写的蠢了
我一开始只是排序后删除最大的2 或 3 个相同数字 ( 取决于最大的相同的有几个),当时知道有可能会出现删除2个最大的不如删除3个最小的情况,赌了一下数据会不会比较弱…… 事实证明CF的数据是很强力的。
下次不应该赌……
错误代码:
#include<algorithm>
#include<iostream>
using namespace std ;
bool comp( int a , int b )
{
return ( a>b) ;
}
int main()
{
int a[5];
for ( int i = 0 ; i < 5 ; i++)
cin >> a[i];
sort(a,a+5,comp);
for ( int i = 0 ; i < 5 ; i++)
{int cnt = 0 ;
int flag = 0 ;
for( int j = i+ 1 ; j < 5 ; j++ )
{int temp = a[i] ;
if( cnt == 2 )break ;
if( a[i] == a[j] )
{a[i] = 0 ;
cnt++;
flag = 1 ;
}
if( temp == a[j] )
{
a[j] = 0 ;
cnt++ ;
}
}
if ( flag == 1 ) break ;
}
cout << a[0]+a[1]+a[2]+a[3]+a[4] << endl ;
}
AC代码:
#include<iostream>
#include<cstring>
using namespace std ;
int main()
{
int a[5] , cnt[110] , s = 0 , ans ;
memset(cnt,0,sizeof(cnt));
for( int i = 0 ; i < 5 ; i++)
{
cin >> a[i] ;
cnt[a[i]]++;
s+=a[i];
}
ans = s ;
for ( int i = 0 ; i < 5 ; i++ )
{
int k ;
if( cnt[a[i]] == 2 )
k = s - (a[i] << 1) ;
else if( cnt[a[i]] > 2 )
k = s - a[i] * 3 ;
if( k < ans )
ans = k ;
}
cout << ans << endl ;
}
A- Bear and Five Cards(codeforces ROUND356 DIV2)的更多相关文章
- 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 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 ...
- Codeforces 731 F. Video Cards(前缀和)
Codeforces 731 F. Video Cards 题目大意:给一组数,从中选一个数作lead,要求其他所有数减少为其倍数,再求和.问所求和的最大值. 思路:统计每个数字出现的个数,再做前缀和 ...
- codeforces 680A A. Bear and Five Cards(水题)
题目链接: A. Bear and Five Cards //#include <bits/stdc++.h> #include <vector> #include <i ...
- 【BZOJ1004】Cards(组合数学,Burnside引理)
[BZOJ1004]Cards(组合数学,Burnside引理) 题面 Description 小春现在很清闲,面对书桌上的N张牌,他决定给每张染色,目前小春只有3种颜色:红色,蓝色,绿色.他询问Su ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- (CodeForces - 5C)Longest Regular Bracket Sequence(dp+栈)(最长连续括号模板)
(CodeForces - 5C)Longest Regular Bracket Sequence time limit per test:2 seconds memory limit per tes ...
- 「日常训练」Watering Flowers(Codeforces Round #340 Div.2 C)
题意与分析 (CodeForces 617C) 题意是这样的:一个花圃中有若干花和两个喷泉,你可以调节水的压力使得两个喷泉各自分别以\(r_1\)和\(r_2\)为最远距离向外喷水.你需要调整\(r_ ...
- 「日常训练」Alternative Thinking(Codeforces Round #334 Div.2 C)
题意与分析 (CodeForces - 603A) 这题真的做的我头疼的不得了,各种构造样例去分析性质... 题意是这样的:给出01字符串.可以在这个字符串中选择一个起点和一个终点使得这个连续区间内所 ...
随机推荐
- Android消息推送之GCM方式(一)
<声明> 转载请保留本来源地址: http://blog.csdn.net/wzg_1987/article/details/9140371 首先,你需要使用一个谷歌账号登录谷歌Api控制 ...
- 作为IT行业计算机从业人士,不要做“邻居盖新房,你就是背后放火的那种人”
金华-普通人(214103872) 21:03:01 尽扯蛋 颇有点凤姐的营销方式 横瓜(601069289) 21:05:16 不服气 你搞一个下面的类似软件出来 http://www.s ...
- HashMap 死循环的探究
大家都知道,HashMap采用链表解决Hash冲突,具体的HashMap的分析可以参考一下http://zhangshixi.iteye.com/blog/672697 的分析.因为是链表结构,那么就 ...
- 初识ionic
1.Ionic环境安装 Ionic开发是依赖于Nodejs环境的,所以在开发之前我们需要安装好Nodejs.下载安装:http://nodejs.org/ 安装完成之后打开PowerShell输入命令 ...
- 结构-行为-样式-AngularJs--指令实现 手动触发响应到页面指定位置
最近工作需要增强用户体验,项目经理说下拉框架用户体验太差,于是乎我开始想了如下指令.这个指令可以让用户点击的时候把下拉或者其他的响应显示的东西不会因为屏幕的滚动而看不见,也就是让用户看见他想看见的. ...
- 使用Spring AOP来进行权限验证
使用Spring AOP前需要先引入相应的包 <dependency> <groupId>org.aspectj</groupId> <artifactId& ...
- 算法笔记_014:合并排序(Java)
1 问题描述 给定一组数据,使用合并排序得到这组数据的非降序排列. 2 解决方案 2.1 合并排序原理简介 引用自百度百科: 合并排序是建立在归并操作上的一种有效的排序算法.该算法是采用分治法(Div ...
- [日记&做题记录]-Noip2016提高组复赛 倒数十天
写这篇博客的时候有点激动 为了让自己不颓 还是写写日记 存存模板 Nov.8 2016 今天早上买了两个蛋挞 吃了一个 然后就做数论(前天晚上还是想放弃数论 但是昨天被数论虐了 woc noip模拟赛 ...
- C# winform调用东软动态库的问题
在C# winform程序中调用东软的动态库ESActiveX.ocx 如果是引用ESActiveX.ocx,然后在代码中设置示例,调用就会报"灾难性错误" 如果在工具箱中点击右键 ...
- CoreJavaE10V1P3.8 第3章 Java的基本编程结构-3.8 控制流程(Control Flow)
通过使用条件语句.循环语句可以实现流程的控制. 3.8.1 块作用域(Block Scope) 块(Block)就是由一对花括号包围起来的部分.他指定了一个变量的生存范围,与一个方法的操作范围. Ja ...