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.
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 "Yes" if it's possible to fulfill the requirements, and "No" otherwise.
You can output each letter in any case (upper or lower).
是个思路,不要被题意迷惑,第一和最后一个为偶数就是no。
如果是偶数个数也是no。
其他可以是1整个数列。{1,2,2,2,2,2,2,2,1}是一个
#include<iostream>
#include<cstdio>
#include <algorithm>
#include <cstring>
#include <set>
using namespace std;
int a[120];
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
if(a[0]%2==0||a[n-1]%2==0) printf("No");
else if(n%2==0) printf("No");
else printf("Yes");
return 0;
}
很尴尬第二题都想不出来。