Codeforces Round #431 (Div. 2)

A. Odds and Ends
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

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.

Input

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

Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise.

You can output each letter in any case (upper or lower).

Examples
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 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一定要是奇数,因为一个偶数不能被分成奇数个奇数。

#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;
}



B. Tell Your World
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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

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).

Examples
input
5
7 5 8 6 9
output
Yes
input
5
-1 -2 0 0 -5
output
No
input
5
5 4 3 2 1
output
No
input
5
1000000000 0 0 0 0
output
Yes
Note

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.



题意:
判断是否存在两条平行不相交的直线覆盖所有点,一条直线上至少有一个点。
比赛的时候看题目完全没看懂意思。。
思路:
因为要覆盖所有点,所以如果可能存在的话,点1、2、3三个点一定在一条或两条线内。k(1,2) , k(1,3) , k(2,3),三个斜率中至少有一个是一条线的斜率。枚举三个斜率,找出在该两点形成直线上的所有点(暴力枚举),然后再判断剩余的点是否在一条直线上就行了。

#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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值