codeforces 849A Odds and Ends
来源:互联网 发布:cctv网络电视播放器 编辑:程序博客网 时间:2024/05/18 19:20
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).
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.
题意:给一个长度为n的序列,能否将这个序列拆成奇数个从奇数开始奇数结束的序列,且每个序列的长度为奇数(题目比较绕,看样例理解一下)
这题看上去很不好下手,想到就很容易,如果n为偶数,将n个数分成奇数分,其中一份里面一定有一个是偶数,因为奇数个奇数相加还是奇数,再判断第一个和最后一个是不是偶数就行,
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<string>#include<stack>#include<queue>#include<deque>#include<set>#include<map>#include<cmath>#include<vector>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int, int> PII;#define pi acos(-1.0)#define eps 1e-10#define pf printf#define sf scanf#define lson rt<<1,l,m#define rson rt<<1|1,m+1,r#define e tree[rt]#define _s second#define _f first#define all(x) (x).begin,(x).end#define mem(i,a) memset(i,a,sizeof i)#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)#define mi ((l+r)>>1)#define sqr(x) ((x)*(x))const int inf=0x3f3f3f3f;int n,a[110];int main(){ while(~sf("%d",&n)) { for1(i,n) sf("%d",&a[i]); if(!(a[1]&1)||!(a[n]&1)||!(n&1)) puts("No"); else puts("Yes"); } return 0;}
- codeforces 849A A.Odds and Ends
- Codeforces 849 A Odds and Ends
- CodeForces-849A Odds and Ends
- codeforces 849A Odds and Ends
- Codeforces 849A. Odds and Ends 结论题,水题
- A. Odds and Ends
- Codeforeces 849A Odds and Ends
- Codeforces Round #431 (Div. 2) A Odds and Ends
- Codeforces Round #431 (Div. 2) A. Odds and Ends
- Codeforces Round #431 (Div. 2) A. Odds and Ends 题解
- CodeForces 431# div.2 A Odds and Ends 暴力 贪心
- Codeforces Round #431 (Div. 2) 849A Odds and Ends(思维)
- Codeforces Round #431 (Div. 2) A. Odds and Ends(找规律)
- A. Odds and Ends Codeforces Round #431 (Div. 2)(水题)
- odds and ends
- cfA. Odds and Ends
- Codeforces849A Odds and Ends
- Odds and Ends
- 数据结构与算法:链表
- 【Linux学习笔记】26:环境变量
- [js高手之路]设计模式系列课程-单例模式实现模态框
- Java反射机制(reflect)
- 多列等高布局
- codeforces 849A Odds and Ends
- HDOJ HDU 1009 FatMouse' Trade
- WOJ1088-从1开始的N个连续自然数的M次方之和
- tcp/ip客户端临时端口
- auto_ptr源码解析以及例子 --auto_ptr_ref
- iOS UICollectionView去除多余分割线
- ajax乱码问题
- Java知识(异常)
- Git