1 second
256 megabytes
standard input
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.
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.
思路:
懒得写了,暴力枚举各种情况讨论。
代码很丑,之前有两个特殊情况没判到,fst了,,直接从rank600 - 1000,是真的脏,心态爆炸。
实现代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<int,int>mp;
int main()
{
ll m,i,j,cnt,a[],b[];
cin>>m;
for(i=;i<=m;i++)
cin>>a[i];
b[] = -;
int len = ;
for(i=;i<=m;i++){
ll ans = a[i]-a[i-];
//cout<<ans<<endl;
cnt = ;
for(j=;j<len;j++)
if(ans!=b[j])
cnt++;
if(cnt == len){
b[len] = ans;len++;
}
}
len--;
//cout<<len<<endl;
if(len == ){
for(i=;i<=m;i++){
ll ans = a[i]-a[i-];
mp[ans]++;
}
if(mp[b[]]==||mp[b[]]==)
cout<<"Yes"<<endl;
else{
int flag = ;
for(i=;i<m;i++){
ll ans1 = a[i] - a[i-];
ll ans2 = a[i+] - a[i];
if(ans1+ans2>max(ans1,ans2))
flag = ;
}
if(flag==) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
else if(len == ){
int k = a[]-a[];
int b = a[] - k*;
int flag = ;
for(i=;i<=m;i++){
if(i*k+b!=a[i]){
flag = ;break;}
}
if(flag == )
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
else if(len==){
sort(b+,b+);
//cout<<b[1]<<endl<<b[2]<<endl<<b[3]<<endl;
if(b[]==*b[]+b[]||b[]==*b[]+b[]||b[]*==b[]+b[])
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
else
cout<<"No"<<endl;
return ;
}