题目描述:
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).
输入:
3
1 3 5
5
1 0 1 5 1
3
4 3 1
4
3 9 9 3
输出:
Yes
Yes
No
No
题意:
能否将这个序列划分成奇数个子序列,其中每个子序列的第一个数字是奇数,最后一个数字也是奇数,而且这个子序列的长度也是奇数
题解:
首先长度为偶数肯定不行,奇数个奇数相加一定为奇数,再就判断一下首尾是不是奇数就可以了
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int a[105];
int main(){
int n;
while(scanf("%d",&n)!=EOF){
bool flag = true;
for(int i = 1; i <= n; i ++) scanf("%d",&a[i]);
if(n % 2 == 0){
flag = false;
}
else if(a[1] % 2 == 0 || a[n] % 2 == 0){
flag = false;
}
if(flag) printf("Yes\n");
else printf("No\n");
}
return 0;
}