Codeforces Tell Your World

来源:互联网 发布:java string类源码分析 编辑:程序博客网 时间:2024/05/29 15:24

题意:

    求给出的点,判断所有点是否都在两条平行线上。第一个点和第二个点的斜率k1,第二个点和第三个点的斜率k2,第一个点和第三个点斜率k3,三个点肯定有两个点在一条直线上,所以三个斜率总有一个是真正的斜率,以第一个点和第二个点作为基准点,判断是否满足斜率相同。代码参考了一位大佬的。

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
57 5 8 6 9
output
Yes
input
5-1 -2 0 0 -5
output
No
input
55 4 3 2 1
output
No
input
51000000000 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.

#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<queue>#include<set>#include<map>#include<cmath>using namespace std;#define maxn 1000005typedef long long ll;int n;int y[1005];bool solve(double  k){    int flag=0;    int point=-1;    for(int i=2;i<=n;i++)    {        if(y[i]-y[1]==k*(i-1))            continue;        flag=1;        if(point<0)            point=i;        else  if(y[i]-y[point]!=(i-point)*k)        {            flag=0;            break;        }    }    if(flag)        return true;    else        return false;}int main(){    cin>>n;    for(int i=1;i<=n;i++)        cin>>y[i];    double k1=(y[2]-y[1])*1.0;    double k2=(y[3]-y[2])*1.0;    double k3=(y[3]-y[1])*0.5;    if(solve(k1)||solve(k2)||solve(k3))        cout<<"Yes"<<endl;    else        cout<<"No"<<endl;    return 0;}


原创粉丝点击