本文主要是介绍Codeforeces 849A 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.
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).
3 1 3 5
Yes
5 1 0 1 5 1
Yes
3 4 3 1
No
4 3 9 9 3
No
第二次打cf。看到第一题就懵了。无从下手的感觉。
想了快一个小时吧,凑出一个dfs来,交了就pretest accept了。
后来听别人说样例只有一个1 1。。。
然后赛后重测。。就wa了 orz
惨遭爆零啊太惨了。。
果然脑洞题不适合我 (可能是做题太少了)
题意:一个序列,让你把它分成奇数个区间,每个区间长度是奇数,并要求以奇数开始和结束。
看了题解意识到,奇数*奇数==奇数。
所以长度必为奇数,长度为奇数,只要头和尾都是奇数就可以了。。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#include <queue>
#include <string>
#define N 1e5+10
using namespace std;
int loc[110],cnt=0,len=0;
int main()
{int n,flag=1,t;cin>>n;if(n%2)for(int i=0;i<n;i++){cin>>t;if(i==0||i==n-1)if(t%2==0){flag=0;break;}}else flag=0;if(flag)cout<<"Yes"<<endl;else cout<<"No"<<endl;return 0;
}
这篇关于Codeforeces 849A Odds and Ends的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!