Codeforces Round #431 (Div. 2) - B. Tell Your World

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



题意:

给你很多个(i,y[i])的点,让你判断能不能形成一对平行线,要用到所有的点。一个点也可以成线(最后一个样例)。


POINT:

选择最前的三个点,他们组成的3个斜率里肯定有一个是真正的k(如果YES)。再判断。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define LL long long
const int maxn =1111;
LL a[maxn];
int n;
bool check(double k)
{
    int p=-1;
    for(int i=2;i<=n;i++)
    {
        if((i-1)*k==a[i]-a[1])
        {
            continue;
        }
        if(p==-1)
        {
            p=i;
        }
        else
        {
            if((i-p)*k!=a[i]-a[p])
                return 0;
        }
    }
    return p!=-1;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    if(check(a[2]-a[1])||check((a[3]-a[1])/2.0)||check(a[3]-a[2]))
    {
        printf("YEs\n");
    }
    else
        printf("NO\n");
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值