Codeforces Round #341 (Div. 2) 总结
来源:互联网 发布:java 视频 最好 编辑:程序博客网 时间:2024/06/02 01:24
Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the n integers, the sum is an even integer 0.
The first line of the input contains one integer, n (1 ≤ n ≤ 100 000). The next line contains n space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive.
Print the maximum possible even sum that can be obtained if we use some of the given integers.
31 2 3
6
5999999999 999999999 999999999 999999999 999999999
3999999996
In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999.
题意:求所给n个数中,远一些数,组成的最大偶数是多少。
解:来一个for循环,把全部数累加起来,再算算这n个数中有多少个是奇数。最后,要是奇数的个数是奇数个,则sum-=min(odd).否则,sum=sum;
<span style="font-size:14px;">#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define LL __int64const LL maxm=1e5+10;LL a[maxm];int main(){ LL n; while(scanf("%I64d",&n)!=EOF) { LL s1=0; LL sum=0; LL Mi=1e9+10; for(LL i=0;i<n;i++) { scanf("%I64d",&a[i]); if(a[i]&1) { s1++; Mi=min(Mi,a[i]); } sum+=a[i]; } if(s1&1) { sum-=Mi; } printf("%I64d\n",sum); } return 0;}</span>
- Codeforces Round #341 (Div. 2) 总结
- Codeforces Round #341 (Div. 2)总结
- Codeforces Round #341 (Div. 2)
- Codeforces Round #341 (Div. 2)
- #Codeforces Round #341 (Div. 2)
- Codeforces Round #161 (Div. 2)总结
- Codeforces Round #162 (Div. 2)总结
- Codeforces Round #170 (Div. 2)总结
- Codeforces Round #171 (Div. 2)总结
- Codeforces Round #172 (Div. 2)总结
- Codeforces Round #173 (Div. 2)总结
- Codeforces Round #176 (Div. 2)总结
- Codeforces Round #185 (Div. 2) 总结
- Codeforces Round #187 (Div. 2) 总结
- Codeforces Round #190 (Div. 2) 总结
- Codeforces Round #193 (Div. 2)总结
- Codeforces Round #194 (Div. 2)总结
- Codeforces Round #204 (Div. 2)总结
- ORA-29491: invalid table for chunking
- 2.* 堆栈
- 【概率与期望】[CodeForces - 621C]Wet Shark and Flowers
- YV12 and NV12
- Java面试笔试题大汇总(最全+详细答案)
- Codeforces Round #341 (Div. 2) 总结
- java开发需要掌握的linux命令
- Fragment的生命周期
- day04 总结
- 三种编程命名规则(匈牙利法,小驼峰法,大驼峰法)
- Android隐藏系统输入法,隐藏软键盘
- OpenCV训练分类器制作xml文档
- linux常用命令的英文单词缩写
- Android setContentView源码解析