您的位置:首页 > 其它

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

2017-09-02 11:09 507 查看
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, thei-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 onexactly one of them, and each of them passes throughat 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 integersy1, 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 points1, 3, 5, and another one that passes through points2, 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三个点出发,分别将这三个点的斜率求出来,这么一来就只有两种情况:1、三个点都在同一直线上,2、至少有两个点在一条直线上。这么一来,我们就可以知道,肯定有两个点是在同一直线上的,这三个斜率,总有一个就是平行线的斜率,然后我们再枚举一下就好了

#include<bits/stdc++.h>
using namespace std;
int n;
int point[1010];
bool judge(double x){
int flag=0;
int po=-1;
for(int i=2;i<=n;i++){
//斜率公式:(y2-y1)=k*(x2-x1)
if(point[i]-point[1]==x*(i-1)) continue;
flag=1;
if(po<0) po=i;
else if(point[i]-point[po]!=x*(i-po)){
flag=0;
break;
}
}
if(flag) return true;
else return false;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++) scanf("%d",&point[i]);
if(judge((point[2]-point[1])*1.0)||judge((
4000
point[3]-point[1])*0.5)||judge(point[3]-point[2]*1.0)){
cout<<"Yes"<<endl;
}
else cout<<"No"<<endl;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: