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
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<iostream>
#include<stdio.h>
using namespace std;
int n,a[105];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
if(a[1]&1 && a[n]&1 && n&1) printf("Yes");
else printf("No");
return 0;
}
Connect the countless points with lines, till we reach the faraway yonder.
There are n points on a coordinate plane, the i-th of which being (i, yi).
Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set.
The first line of input contains a positive integer n (3 ≤ n ≤ 1 000) — the number of points.
The second line contains n space-separated integers y1, y2, ..., yn ( - 109 ≤ yi ≤ 109) — the vertical coordinates of each point.
Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise.
You can print each letter in any case (upper or lower).
5 7 5 8 6 9
Yes
5 -1 -2 0 0 -5
No
5 5 4 3 2 1
No
5 1000000000 0 0 0 0
Yes
In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one.
In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel.
In the third example, it's impossible to satisfy both requirements at the same time.
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#define LL long long
using namespace std;
LL n,h[1010],vis[1010];
double k1,k2,k3;
double ans_k(int a,int b) {return (h[a]-h[b])*1.0/(a-b);}
bool ans(double k,int x1,int x2)
{
memset(vis, 0, sizeof vis);
vis[x1] = vis[x2] = 1;
LL cnt = 2;
for(int i=1;i<=n;i++)
{
if(vis[i]) continue;
if(fabs(ans_k(x1, i)-k)<1e-6) vis[i] = 1,cnt++;
}
int st = 1010;
for(int i=1;i<=n;i++)
{
if(vis[i]) continue;
st=i;cnt++;break;
}
for(int i=st+1;i<=n;i++)
{
if(vis[i]||fabs(ans_k(st, i)-k)>1e-6) continue;
vis[i] = 1,cnt++;
}
if(cnt==n&&st<=n) return true;
return false;
}
int main()
{
scanf("%lld",&n);
for(int i=1;i<=n;i++) scanf("%lld",&h[i]);
k1 = ans_k(1,2),k2 = ans_k(1,3),k3 = ans_k(2, 3);
if(ans(k1,1,2)||ans(k2,1,3)||ans(k3,2,3))
{
printf("Yes");
return 0;
}
printf("No");
return 0;
}