Odds and Ends

来源:互联网 发布:阿里云第三方接口 编辑:程序博客网 时间:2024/05/18 16:55

Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?

Given an integer sequence a1, a2, ..., an of lengthn. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.

A subsegment is a contiguous slice of the whole sequence. For example,{3, 4, 5} and {1} are subsegments of sequence{1, 2, 3, 4, 5, 6}, while {1, 2, 4} and{7} are not.

Input

The first line of input contains a non-negative integer n (1 ≤ n ≤ 100) — the length of the sequence.

The second line contains n space-separated non-negative integersa1, a2, ..., an (0 ≤ ai ≤ 100) — the elements of the sequence.

Output

Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise.

You can output each letter in any case (upper or lower).

Example
Input
31 3 5
Output
Yes
Input
51 0 1 5 1
Output
Yes
Input
34 3 1
Output
No
Input
43 9 9 3
Output
No
Note

In the first example, divide the sequence into 1 subsegment:{1, 3, 5} and the requirements will be met.

In the second example, divide the sequence into 3 subsegments:{1, 0, 1}, {5}, {1}.

In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.

In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.

题意:给一个数字集合,问能否把集合拆分奇数个子集合组成·且每个集合首尾都是奇数,每个集合元素个数为奇数组。
想了半天看博客,发现由奇数个数组成的奇数个集合,这样总元素的个数一定为奇数,首位和末尾一定的是奇数。满足这个条件的话一定能有一个满足条件的集合就是他本身,。否则不可能满足题意。
代码:
#include<cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>using namespace std;int main(){    int n,x,y;    scanf("%d",&n);    scanf("%d",&x);    for(int i=1;i<n;i++)        scanf("%d",&y);    if(n==1)    {        if(x%2)            printf("Yes\n");        else            printf("No\n");        return 0;    }    if(n%2==0||x%2==0||y%2==0)        printf("No\n");    else        printf("Yes\n");    return 0;}


原创粉丝点击