Codeforeces 849A Odds and Ends

来源:互联网 发布:优化产业结构什么意思 编辑:程序博客网 时间:2024/05/05 07:12
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

第二次打cf。看到第一题就懵了。无从下手的感觉。

想了快一个小时吧,凑出一个dfs来,交了就pretest accept了。
后来听别人说样例只有一个1  1。。。
然后赛后重测。。就wa了 orz
惨遭爆零啊太惨了。。
果然脑洞题不适合我 (可能是做题太少了)
题意:一个序列,让你把它分成奇数个区间,每个区间长度是奇数,并要求以奇数开始和结束。
看了题解意识到,奇数*奇数==奇数。
所以长度必为奇数,长度为奇数,只要头和尾都是奇数就可以了。。

#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <vector>#include <cmath>#include <cstring>#include <queue>#include <string>#define N 1e5+10using namespace std;int loc[110],cnt=0,len=0;int main(){int n,flag=1,t;cin>>n;if(n%2)for(int i=0;i<n;i++){cin>>t;if(i==0||i==n-1)if(t%2==0){flag=0;break;}}else flag=0;if(flag)cout<<"Yes"<<endl;else cout<<"No"<<endl;    return 0;}


原创粉丝点击