cf 59B Fortune Telling

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
题意:主人公摘花瓣判断女主是否爱她,奇数爱,偶数不爱,主人公总是希望女主爱上他,且摘掉的花瓣尽量多。
思路:贪心,先判断所有的数目是否为偶数,是则直接输出,否则减去一个最小的奇数输出。

#include<cstdio>                                                             //*
#include<cstring>                                                            //*
#include<algorithm>                                                          //*
#include<iostream>                                                           //*
#include<vector>                                                             //*
#include<map>                                                                //*
#include<set>                                                                //*
#include<queue>                                                              //*
#include<stack>                                                              //*
#include<cmath>                                                              //*
#include<list>                                                               //*
#define ll long long                                                         //*
#define INT __int64                                                          //*
#define usn unsigned                                                         //*
const ll INF = 0x3f3f3f3f;                                                  //*
const int _INF = 0x80000000;                                                 //*
ll gcd(ll a,ll b){while(b^=a^=b^=a%=b);return a;}                            //*
ll lcd(ll a , ll b){return a * b / gcd(a,b);}                                //*
inline int read(){                                                           //*
    char ch = getchar(); int x = 0, f = 1;                                   //*
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}      //*
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}   //*
    return x * f;                                                            //*
}                                                                            //*
inline void write(int x)                                                     //*
{                                                                            //*
    if(x<0) {                                                                //*
        putchar('-');                                                        //*
        x = -x;                                                              //*
    }                                                                        //*
    if(x>9) write(x / 10);                                                   //*
    putchar(x % 10 + '0');                                                   //*
}                                                                            //*
using namespace std;                                                         //*
//---------------------------------------------------------------------------//*
  int main(){
    int n;
      cin >> n;
        int a[110];
         int tot = 0;
          for(int i = 0 ; i < n ; i ++){
              cin >> a[i];
               tot += a[i];
          }
        sort(a,a+n);
      if(tot % 2){
          cout << tot << endl;
      }else{
          for(int i = 0 ;  i < n ;  i++)
             if(a[i] % 2){
                tot -= a[i];
                break;
             }
            if(tot % 2) cout << tot << endl;
             else cout << 0 << endl;
      }

  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值