Wet Shark and Oddand Even
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit Status
Description
Today,Wet Shark is given n integers.Using any of these integers no more than once, Wet Shark wants to get maximumpossible 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.
Input
Thefirst line of the input contains one integer, n (1 ≤ n ≤ 100 000).The next line contains n spaceseparated integers given to Wet Shark. Each of these integers is in range from 1 to 109,inclusive.
Output
Printthe maximum possible even sum that can be obtained if we use some of the givenintegers.
Sample Input
Input
3
1 2 3
Output
6
Input
5
999999999 999999999 999999999 999999999 999999999
Output
3999999996
就是看一组数字组成的最大的偶数
思路:标记奇数的最小值,如果ans是奇数则减去该值
/*=============================AC情况===============================*/
/*题目网址: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=117765#problem/A */
/*时间:2016年5月27日21:45:49 */
/*心得: */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define G 100
int main() {
int t,min,n;
long long ans;
while(scanf("%d",&t)!=EOF) {
ans=0;
min=-1;
for(int j=1; j<=t; j++) {
scanf("%d",&n);
ans=ans+n;
if(min==-1&&(n%2!=0))
min=n;
if(n<min&&(n%2!=0))
min=n;
}
if(ans%2==0)
printf("%lld\n",ans);
else
printf("%lld\n",ans-min);
}
return 0;
}
/*********************************测试数据*********************************
Input
3
1 2 3
Output
6
Input
5
999999999 999999999 999999999 999999999 999999999
Output
3999999996
**************************************************************************/

本文介绍了一道编程题,目标是使用给定的一组整数中的一部分,使得这些整数的和为最大的偶数值。文章提供了AC代码示例,通过记录最小奇数值并在总和为奇数时减去它来确保结果为偶数。
2203

被折叠的 条评论
为什么被折叠?



