Codeforces849A Odds and Ends

45 篇文章 0 订阅
40 篇文章 0 订阅

标签:模拟

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

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

A subsegment is a contiguous slice of thewhole 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 anon-negative integern (1 ≤ n ≤ 100) — the length of the sequence.

The second line containsn space-separatednon-negative integers a1, a2, ..., an (0 ≤ ai ≤ 100) — the elementsof the sequence.

Output

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

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

Example

Input

3
1 3 5

Output

Yes

Input

5
1 0 1 5 1

Output

Yes

Input

3
4 3 1

Output

No

Input

4
3 9 9 3

Output

No

Note

In the first example, divide the sequenceinto 1 subsegment: {1, 3, 5} and therequirements will be met.

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

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

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

 

题意:给定一个序列,判断其是否可以分成奇数个非空的子段,并且这些子段长度都为奇数,开头和结尾都是奇数

分析:用递归的写法,从头开始找当前最长的子段,暴力枚举,水题

参考代码

#include<bits/stdc++.h>
inline int read() 
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,ans=0,flag;
int a[105];

void work(int l,int r)
{
	if(a[l]%2==0){flag=0;return;}
	int i;
	ans++;//printf("%d %d %d\n",l,r,ans);
	for(i=r;i>=l;i--)
	    if((i-l)%2==0&&a[i]%2!=0){break;}
	if(i<r)work(i+1,r);
}
int main()
{
	for(int i=1;i<105;i++)a[i]=2;
    n=read();
    for(int i=1;i<=n;i++)a[i]=read();
    if(a[1]%2==0||a[n]%2==0){printf("No\n");return 0;}
    flag=1;
    work(1,n);
    if(ans%2==0||flag==0)printf("No\n");
    else printf("Yes\n");
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值