Odds and Ends
来源:互联网 发布:阿里云第三方接口 编辑:程序博客网 时间:2024/05/18 16:55
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 lengthn. 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 integersa1, 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).
31 3 5
Yes
51 0 1 5 1
Yes
34 3 1
No
43 9 9 3
No
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.
#include<cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>using namespace std;int main(){ int n,x,y; scanf("%d",&n); scanf("%d",&x); for(int i=1;i<n;i++) scanf("%d",&y); if(n==1) { if(x%2) printf("Yes\n"); else printf("No\n"); return 0; } if(n%2==0||x%2==0||y%2==0) printf("No\n"); else printf("Yes\n"); return 0;}
- odds and ends
- cfA. Odds and Ends
- Codeforces849A Odds and Ends
- A. Odds and Ends
- Odds and Ends
- Codeforces 849 A Odds and Ends
- CodeForces-849A Odds and Ends
- codeforces 849A A.Odds and Ends
- Codeforeces 849A Odds and Ends
- codeforces 849A Odds and Ends
- Codeforces Round #431 (Div. 2) A Odds and Ends
- Codeforces Round #431 (Div. 2) Odds and Ends
- Codeforces Round #431 (Div. 2) A. Odds and Ends
- Codeforces 849A. Odds and Ends 结论题,水题
- Codeforces Round #431 (Div. 2) A. Odds and Ends 题解
- CodeForces 431# div.2 A Odds and Ends 暴力 贪心
- 【odds and ends】均方差和均方误差
- Codeforces Round #431 (Div. 2) 849A Odds and Ends(思维)
- Swift4.0中setValuesForKeys()不起作用的问题
- cookies工具类
- MVP入门,接口回调两种实现,new接口和implement实现,okhttpclient
- 04 H5使用usb_otg接口作虚拟设备
- 奥威Power-BI For 电力行业方案-三相不平衡分析
- Odds and Ends
- linux下gdb调试QT程序时,报错,错误如下:
- JSP学习笔记—EL表达式和JSTL标签详解
- 【树形dp】贪吃的九头龙
- jeecg 在tomact8+jdk8下 运行报 URL must not be null
- Intelij IDEA中修改maven为阿里云
- JUnit4之BlockJUnit4ClassRunner
- 自定义弧形进度条,百分比的值在变化
- CSDN查看网址