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 }

Codeforces 849A:Odds and Ends(思维)的更多相关文章

  1. A. Odds and Ends(思维)

    A. Odds and Ends time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  2. 【Codeforces Round #431 (Div. 2) A】Odds and Ends

    [链接]点击打开链接 [题意] 让你把一个数组分成奇数个部分. 且每个部分的长度都是奇数. [题解] 很简单的脑洞题. 开头和结尾一定要为奇数,然后 n为奇数的话,就选整个数组咯. n为偶数的话,不能 ...

  3. CodeForces - 427A (警察和罪犯 思维题)

    Police Recruits Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  4. codeforces 895B XK Segments 二分 思维

    codeforces 895B XK Segments 题目大意: 寻找符合要求的\((i,j)\)对,有:\[a_i \le a_j \] 同时存在\(k\),且\(k\)能够被\(x\)整除,\( ...

  5. codeforces 893D Credit Card 贪心 思维

    codeforces 893D Credit Card 题目大意: 有一张信用卡可以使用,每天白天都可以去给卡充钱.到了晚上,进入银行对卡的操作时间,操作有三种: 1.\(a_i>0\) 银行会 ...

  6. E. Superhero Battle Codeforces Round #547 (Div. 3) 思维题

    E. Superhero Battle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  8. C Alyona and Spreadsheet Codeforces Round #401(Div. 2)(思维)

    Alyona and Spreadsheet 这就是一道思维的题,谈不上算法什么的,但我当时就是不会,直到别人告诉了我,我才懂了的.唉 为什么总是这么弱呢? [题目链接]Alyona and Spre ...

  9. codeforces 848B Rooter's Song 思维题

    http://codeforces.com/problemset/problem/848/B 给定一个二维坐标系,点从横轴或纵轴垂直于发射的坐标轴射入(0,0)-(w,h)的矩形空间.给出点发射的坐标 ...

随机推荐

  1. three.js很好玩

    能用鼠标拉着转. https://files.cnblogs.com/files/blogs/714801/%E7%A9%BA%E9%97%B4%E5%87%A0%E4%BD%95.7z var po ...

  2. 关于redis HSCAN count参数不生效的问题

    这的确是个坑,HSCAN是为了处理大量数据而设计的,可能也是因为这个原因,在数据量较少的情况下count参数并不会生效,具体阈值是多少并没有实际测验过不过可以断定的是一百条数据一下估计是不会生效的.

  3. 从源码看Thread&ThreadLocal&ThreadLocalMap的关系与原理

    1.三者的之间的关系 ThreadLocalMap是Thread类的成员变量threadLocals,一个线程拥有一个ThreadLocalMap,一个ThreadLocalMap可以有多个Threa ...

  4. Docker学习(三)——Docker镜像使用

    Docker镜像使用     当运行容器时,使用的镜像如果在本地中不存在,docker就会自动从docker镜像仓库中下载,默认是从Docker Hub公共镜像源下载. 1.镜像使用     (1)列 ...

  5. zabbix之修改中文

    #在zabbix服务器安装中文名包 root@ubuntu:~# sudo apt-get install language-pack-zh* #:修改环境变量 root@ubuntu:~# sudo ...

  6. Dubbo应用到web工程

    一.创建提供者03-provider-web (1) 创建工程 创建Maven的web工程,然后创建实现类. (2) 导入依赖 Spring的版本为4.3.16 需要的依赖有: dubbo2.7.0版 ...

  7. css clip样式 属性功能及作用

    clip clip 在学前端的小伙伴前,估计是很少用到的,代码中也是很少看见的,但是,样式中有这样的代码,下面让我们来讲讲他吧! 这个我也做了很久的开发没碰到过这个属性,知道我在一个项目中,有一个功能 ...

  8. 【Matlab】线性调频信号LFM 仿真

    [知识点] 生成序列 i = a:step:b 举例: i = 1:1:9 画图(子图) subplot(m,n,p)或者subplot(m n p) 总结起来就是,画一个m行n列的图. p表示在第p ...

  9. [BUUCTF]PWN——[ZJCTF 2019]Login

    [ZJCTF 2019]Login 附件 步骤: 例行检查,64位程序,开启了canary和nx保护 2. 试运行一下程序 3. 64位ida载入,检索字符串,在程序里找到了用户名admin和密码2j ...

  10. 2019"深思杯"山东省大学生网络安全技能大赛部分wp

    签到 载入OD查看字符串 上下左右 这道题出来的时候真的是一点思路都没有,一直以为是什么编码来着,看了大佬们的 wp 原来是画图 拿大佬的脚本: from PIL import Image im = ...