Codeforces--849A--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.
输入描述:
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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值