• Codeforces 849A: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.

    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
    ";
    33         return 0;
    34     }
    35     if(!a[0]||!a[n-1])
    36     {
    37         cout<<"No
    ";
    38         return 0;
    39     }
    40     cout<<"Yes
    ";
    41     #ifndef ONLINE_JUDGE
    42         cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
    43     #endif
    44     return 0;
    45 }
  • 相关阅读:
    【SCP-GO-100】梦 中 染
    【scp系列】SCP-4711 不便利便利店
    【scp系列】SCP-2298 塑料盒里的生活
    【scp系列】SCP-CN-1219 关云长大战外星人
    【scp系列】SCP-4444 以米斯达之名
    使用Ubuntu搭建Owncloud私有云
    python中函数的使用初步
    IOS自动化环境搭建踩坑指南
    接口测试工具apifox
    windowns上搭建vscode+node.js开发环境
  • 原文地址:https://www.cnblogs.com/Friends-A/p/11372794.html
Copyright © 2020-2023  润新知