codeforces 849A Odds and Ends

来源:互联网 发布:cctv网络电视播放器 编辑:程序博客网 时间:2024/05/18 19:20

A. Odds and Ends
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 length n. 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.

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 integers a1, 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).

Examples
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.



题意:给一个长度为n的序列,能否将这个序列拆成奇数个从奇数开始奇数结束的序列,且每个序列的长度为奇数(题目比较绕,看样例理解一下)

这题看上去很不好下手,想到就很容易,如果n为偶数,将n个数分成奇数分,其中一份里面一定有一个是偶数,因为奇数个奇数相加还是奇数,再判断第一个和最后一个是不是偶数就行,



#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<string>#include<stack>#include<queue>#include<deque>#include<set>#include<map>#include<cmath>#include<vector>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int, int> PII;#define pi acos(-1.0)#define eps 1e-10#define pf printf#define sf scanf#define lson rt<<1,l,m#define rson rt<<1|1,m+1,r#define e tree[rt]#define _s second#define _f first#define all(x) (x).begin,(x).end#define mem(i,a) memset(i,a,sizeof i)#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)#define mi ((l+r)>>1)#define sqr(x) ((x)*(x))const int inf=0x3f3f3f3f;int n,a[110];int main(){    while(~sf("%d",&n))    {        for1(i,n)            sf("%d",&a[i]);        if(!(a[1]&1)||!(a[n]&1)||!(n&1))            puts("No");        else            puts("Yes");    }    return 0;}


原创粉丝点击