Codeforces849A Odds and Ends
来源:互联网 发布:w7 mysql更改密码 编辑:程序博客网 时间:2024/05/18 17:01
标签:模拟
Where do odds begin, and where do they end?Where does hope emerge, and will they ever break?
Given an integer sequencea1, a2, ..., an of lengthn. Decide whether it is possible to divide it intoan odd number of non-empty subsegments, the each of which has an odd length andbegins and ends with odd numbers.
A subsegment is a contiguous slice of thewhole 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 anon-negative integern (1 ≤ n ≤ 100) — the length of the sequence.
The second line containsn space-separatednon-negative integersa1, a2, ..., an (0 ≤ ai ≤ 100) — the elementsof the sequence.
Output
Output "Yes" if it's possible tofulfill the requirements, and "No" otherwise.
You can output each letter in any case(upper or lower).
Example
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 sequenceinto 1 subsegment: {1, 3, 5} and therequirements will be met.
In the second example, divide the sequenceinto 3 subsegments: {1, 0, 1}, {5}, {1}.
In the third example, one of thesubsegments must start with 4 which is an even number, thus the requirementscannot be met.
In the fourth example, the sequence can bedivided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an evennumber.
题意:给定一个序列,判断其是否可以分成奇数个非空的子段,并且这些子段长度都为奇数,开头和结尾都是奇数
分析:用递归的写法,从头开始找当前最长的子段,暴力枚举,水题
参考代码
#include<bits/stdc++.h>inline int read() {int f=1,x=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}int n,ans=0,flag;int a[105];void work(int l,int r){if(a[l]%2==0){flag=0;return;}int i;ans++;//printf("%d %d %d\n",l,r,ans);for(i=r;i>=l;i--) if((i-l)%2==0&&a[i]%2!=0){break;}if(i<r)work(i+1,r);}int main(){for(int i=1;i<105;i++)a[i]=2; n=read(); for(int i=1;i<=n;i++)a[i]=read(); if(a[1]%2==0||a[n]%2==0){printf("No\n");return 0;} flag=1; work(1,n); if(ans%2==0||flag==0)printf("No\n"); else printf("Yes\n"); return 0;}
- Codeforces849A Odds and Ends
- odds and ends
- cfA. 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(思维)
- js作用域
- 【Linux学习笔记】33:环境变量配置文件简介
- 机器学习和计算机视觉库
- 【Java基础】概述
- [POI2000]病毒 [洛谷]P2444
- Codeforces849A Odds and Ends
- 利用Python创建链接mysql数据库个性化对象
- spark partitioner使用技巧
- 二叉树的最大深度
- JSP的7个动作指令
- jmeter解决响应数据乱码问题
- C# winform把新值写入app.config文件
- (六)Interacting with Other Apps与其他应用进行交互
- 什么是事件委托?