2016.13周 周练A - Wet Shark and Odd and Even【CF】
2016-05-25 19:09
537 查看
A - Wet Shark and Odd and 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 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.
Input
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.
Output
Print the maximum possible even sum that can be obtained if we use some of the given integers.
Sample Input
Input
Output
Input
Output
Hint
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.
题意:给一组数,含偶数和奇数,问相加的偶数和最大为多少。
解:
当奇数有2N+1个时,所有数的和减去最小的奇数;
当奇数有2N个时,就求所有数的和。
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int n;
long long a[100010],s1,s2,m,ans;
while(~scanf("%d",&n))
{
s1=0;
ans=0;
for(int i=0;i<n;i++)
{
scanf("%lld",&a[i]);
s1+=a[i];
if(a[i]%2==1)
ans++;
}
sort(a,a+n);
m=0;
if(ans%2==1)
{
for(int i=0;i<n;i++)
{
if(a[i]%2==1)
{
m=a[i];
break;
}
}
}
s2=s1-m;
printf("%lld\n",s2);
}
return 0;
}
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 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.
Input
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.
Output
Print the maximum possible even sum that can be obtained if we use some of the given integers.
Sample Input
Input
3 1 2 3
Output
6
Input
5 999999999 999999999 999999999 999999999 999999999
Output
3999999996
Hint
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.
题意:给一组数,含偶数和奇数,问相加的偶数和最大为多少。
解:
当奇数有2N+1个时,所有数的和减去最小的奇数;
当奇数有2N个时,就求所有数的和。
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int n;
long long a[100010],s1,s2,m,ans;
while(~scanf("%d",&n))
{
s1=0;
ans=0;
for(int i=0;i<n;i++)
{
scanf("%lld",&a[i]);
s1+=a[i];
if(a[i]%2==1)
ans++;
}
sort(a,a+n);
m=0;
if(ans%2==1)
{
for(int i=0;i<n;i++)
{
if(a[i]%2==1)
{
m=a[i];
break;
}
}
}
s2=s1-m;
printf("%lld\n",s2);
}
return 0;
}
相关文章推荐
- Python之路,Day3
- Sql Server 常用函数
- 矩阵鞍点代码
- 【NOIP2013模拟】Freda的传呼机
- 专家的修炼之路 —— 德雷福斯模型
- 北京海淀驾校学车经验
- 二进制(1):无符号编码和补码编码
- 用java来创建链表
- 超越学XML与DTD技术总结笔记(之三)
- 正则表达式基本语法
- Ruby编写HTML脚本替换小程序的实例分享
- centos 安装mount
- 【bzoj4551】[Tjoi2016&Heoi2016]树
- 开源的人工智能项目 Torch 和 FacebookAI 工具
- 【GDOI2014模拟】雨天的尾巴
- CSS布局自适应等分比例实践
- 超越学XML与DTD技术总结笔记(之二)
- Android Studio不打印Logcat解决!
- 原创:C++实现的可排序的双向链表
- uva 11584 划分成回文串