天天看點

Codeforces 849A:Odds and Ends(思維)A. Odds and Ends題意思路代碼

A. Odds and Ends

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.

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

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 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為偶數的時候,那麼一定是不符合題目要求的

然後,因為要劃分成奇數個子序列,因為1也是奇數,是以隻需要判斷整個數組的第一個和最後一個元素是不是奇數就可以了,如果其中有一個不是奇數,那麼一定不符合要求

代碼

1 #include <bits/stdc++.h>
 2 #define ll long long
 3 #define ull unsigned long long
 4 #define ms(a,b) memset(a,b,sizeof(a))
 5 const int inf=0x3f3f3f3f;
 6 const ll INF=0x3f3f3f3f3f3f3f3f;
 7 const int maxn=1e6+10;
 8 const int mod=1e9+7;
 9 const int maxm=1e3+10;
10 using namespace std;
11 int a[maxm];
12 int main(int argc, char const *argv[])
13 {
14     #ifndef ONLINE_JUDGE
15         freopen("/home/wzy/in.txt", "r", stdin);
16         freopen("/home/wzy/out.txt", "w", stdout);
17         srand((unsigned int)time(NULL));
18     #endif
19     ios::sync_with_stdio(false);
20     cin.tie(0);
21     int n;
22     cin>>n; 
23     int sum=0;
24     for(int i=0;i<n;i++)
25     {
26         cin>>a[i];
27         a[i]&=1;
28         sum+=a[i];
29     }
30     if(!(n&1))
31     {
32         cout<<"No\n";
33         return 0;
34     }
35     if(!a[0]||!a[n-1])
36     {
37         cout<<"No\n";
38         return 0;
39     }
40     cout<<"Yes\n";
41     #ifndef ONLINE_JUDGE
42         cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
43     #endif
44     return 0;
45 }      

轉載于:https://www.cnblogs.com/Friends-A/p/11372794.html