Codeforces59 B - Fortune Telling(再水)

B. Fortune Telling
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively “Loves” and “Doesn’t love”, at that Marina always starts with “Loves”. There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, … an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be “Loves”. Help her do that; find the maximal number of petals possible in the bouquet.

Input
The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile.

Output
Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in “Loves”. If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower.

Examples
input
1
1
output
1
input
1
2
output
0
input
3
5 6 7
output
13
分析
题意:有n束花,每束花都有a[i]个花瓣,求在这n束花中选出几束花,使得这几束花的花瓣总数为最大奇数(奇数就表白),输出这几束花总的花瓣数目.
思路:
n个数,找到这n个数中最小的奇数x,并求出这n个数的和sum
如果sum是奇数,printf sum
如果sum是偶数,print sum-x

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
using namespace std;

int a[105];
int main(){
    int n;
    scanf("%d",&n);
    int sum=0;
    int mi=105;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]&1)
            mi=min(mi,a[i]);
        sum+=a[i];
    }
    if(sum&1){
        printf("%d\n",sum);
    }
    else{
        if(mi!=105)
            printf("%d\n",sum-mi);
        else
            printf("0\n");
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值