Codeforces Round #341 (Div. 2) A. Wet Shark and Odd and Even (水)
来源:互联网 发布:数据库架构师职责 编辑:程序博客网 时间:2024/05/22 12:01
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 by2) 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 integer0.
The first line of the input contains one integer, n (1 ≤ n ≤ 100 000). The next line containsn space separated integers given to Wet Shark. Each of these integers is in range from1 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个数,求其能组成的最大偶数和
思路:求总和,然后查看总和是奇数的话减去最小的那个奇数,如果是偶数就是答案
ac代码:
#include<stdio.h>#include<math.h>#include<string.h>#include<stack>#include<set>#include<queue>#include<vector>#include<iostream>#include<algorithm>#define MAXN 100010#define LL long long#define ll __int64#define INF 0x7fffffff#define mem(x) memset(x,0,sizeof(x))#define PI acos(-1)#define eps 1e-10using namespace std;int gcd(int a,int b){return b?gcd(b,a%b):a;}LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}//headll num[MAXN];int v[MAXN];int main(){int n,i,j;while(scanf("%d",&n)!=EOF){ll mi=INF;ll ans=0;ll a;mem(v);for(i=0;i<n;i++){scanf("%I64d",&a);if(a%2)mi=min(mi,a);ans+=a;}if(ans%2){printf("%I64d\n",ans-mi);}else{printf("%I64d\n",ans);}}return 0;}
- Codeforces Round #341 (Div. 2) A. Wet Shark and Odd and Even (水)
- Codeforces Round #341 (Div. 2) --A. Wet Shark and Odd and Even
- Codeforces Round #341 (Div. 2)-A. Wet Shark and Odd and Even(奇数+奇数为偶数)
- Codeforces Round #341 (Div. 2)A Wet Shark and Odd and Even
- Codeforces Round #341 (Div. 2) CF621A. Wet Shark and Odd and Even
- Codeforces 621A Wet Shark and Odd and Even
- Codeforces 621A Wet Shark and Odd and Even 【水题】
- Codeforces 621A Wet Shark and Odd and Even
- CodeForces 621A-Wet Shark and Odd and Even
- CodeForces 621 A Wet Shark and Odd and Even
- 【CodeForces】[621A]Wet Shark and Odd and Even
- CodeForces A. Wet Shark and Odd and Even
- codeforces 621A Wet Shark and Odd and Even
- A. Wet Shark and Odd and Even
- CodeForces--621A--Wet Shark and Odd and Even(数学水题)
- CodeForces 621 A. Wet Shark and Odd and Even(水~)
- 【CodeForces】#621A - Wet Shark and Odd and Even(水)
- Codeforces Round #341 (Div. 2)AWet Shark and Odd and Even
- UrlRewrite伪静态设置以后真的html页面无法访问的问题
- 萨达是
- linux tcp高并发
- 机器学习笔记(二)数理统计
- 坚持的力量
- Codeforces Round #341 (Div. 2) A. Wet Shark and Odd and Even (水)
- Tomcat中如何配置首页面,虚拟目录。
- Ubuntu基本服务配置笔记
- 用mimikatz来获取win7的密码
- Python Flask框架
- 机器学习笔记(二)矩估计,极大似然估计
- Codeforces Round #341 (Div. 2) B. Wet Shark and Bishops (正副对角线规律)
- Nodejs,我竟无言以对
- Putty 使用密钥远程登录到linux