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 points1, 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 我们把1和i的斜率算一算,然后符合条件的都标记

3 剩下的再算一算斜率,然后发现有没有不等于这个斜率的,不等于返回第二步 i+1

4 因为我们1这个点已经当做确定点了,我们需要特殊考虑一下 比如 1 4 5 6这种情况

5 还有其他细节自己判断一下

 #include<bits/stdc++.h>
using namespace std;
double x[];
set<double>Se;
double ans;
int main(){
int n;
int flag=;
cin>>n;
cin>>x[];
cin>>x[];
ans=x[]-x[];
for(int i=;i<=n;i++){
cin>>x[i];
if(x[i]-x[i-]!=ans){
flag=;
}
}
if(x[]-x[]!=ans){
int flag3=;
double cnt=x[]-x[];
for(int i=;i<=n;i++){
if(x[i]-x[i-]!=cnt){
flag3=;
}
}
if(flag3==){
cout<<"Yes"<<endl;
return ;
}
}
for(int i=;i<=n;i++){
Se.insert(x[i]);
}
if(Se.size()==){
cout<<"No"<<endl;
return ;
}
if(Se.size()==){
cout<<"Yes"<<endl;
return ;
}
if(flag==){
cout<<"No"<<endl;
return ;
}else{
map<int,int>Mp;
double lv;
Mp[]=;
for(int i=;i<=n;i++){
Mp.clear();
Mp[i]=;
lv=(x[i]-x[])/(i-)*1.0;
// cout<<lv<<" "<<i<<endl;
for(int j=;j<=n;j++){
if(Mp[j]) continue;
//cout<<(x[j]-x[1])/(j-1)<<" "<<j<<endl;
if((x[j]-x[])/(j-)==lv){
Mp[j]=;
}
}
int x1;
for(int j=;j<=n;j++){
if(Mp[j]==){
x1=j;
Mp[j]=;
break;
}
}
// cout<<x1<<endl;
int flag1=;
for(int j=;j<=n;j++){
if(Mp[j]==){
// cout<<(x[j]-x[x1])/(j-x1)<<"B"<<x1<<" "<<j<<endl;
if((x[j]-x[x1])/(j-x1)!=lv){
flag1=;
}
}
}
if(flag1==){
cout<<"Yes"<<endl;
return ;
}
}
}
cout<<"No"<<endl;
return ;
}

官方题解:我们只要讨论1 2 3点就行。不管怎么分,平行线都会经过这3点,复杂度变为O(n)

 #include <bits/stdc++.h>
#define eps 1e-7
using namespace std;
int read()
{
int x=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,a[];
bool vis[];
bool check(double k,int b)
{
memset(vis,false,sizeof(vis));
int cnt=;
for (int i=;i<=n;i++)
{
if (a[i]-b==1LL*k*(i-))
{
vis[i]=true;
++cnt;
}
}
if (cnt==n) return false;
if (cnt==n-) return true;
int pos1=;
for (int i=;i<=n;i++)
if (!vis[i]&&pos1==) pos1=i;
for (int i=pos1+;i<=n;i++)
if (!vis[i])
{
if (fabs((double)(a[i]-a[pos1])/(i-pos1)-k)>eps) return false;
}
return true;
}
int main()
{
n=read();
for (int i=;i<=n;i++)
a[i]=read();
bool ans=false;
ans|=check(1.0*(a[]-a[]),a[]);
ans|=check(0.5*(a[]-a[]),a[]);
ans|=check(1.0*(a[]-a[]),a[]*-a[]);
if (ans) printf("Yes\n"); else printf("No\n");
return ;
}

Codeforces Round #431 (Div. 2) B的更多相关文章

  1. Codeforces Round #431 (Div. 1)

    A. From Y to Y time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. Codeforces Round #431 (Div. 2) C. From Y to Y

    题目: C. From Y to Y time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  3. Codeforces Round #431 (Div. 2)

    A. Odds and Ends Where do odds begin, and where do they end? Where does hope emerge, and will they e ...

  4. Codeforces Round #431 (Div. 2) C

    From beginning till end, this message has been waiting to be conveyed. For a given unordered multise ...

  5. 【Codeforces Round #431 (Div. 1) D.Shake It!】

    ·最小割和组合数放在了一起,产生了这道题目. 英文题,述大意:     一张初始化为仅有一个起点0,一个终点1和一条边的图.输入n,m表示n次操作(1<=n,m<=50),每次操作是任选一 ...

  6. 【Codeforces Round 431 (Div. 2) A B C D E五个题】

    先给出比赛地址啦,感觉这场比赛思维考察非常灵活而美妙. A. Odds and Ends ·述大意:      输入n(n<=100)表示长度为n的序列,接下来输入这个序列.询问是否可以将序列划 ...

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

  8. 【推导】【分类讨论】Codeforces Round #431 (Div. 1) B. Rooter's Song

    给你一个这样的图,那些点是舞者,他们每个人会在原地待ti时间之后,以每秒1m的速度向前移动,到边界以后停止.只不过有时候会碰撞,碰撞之后的转向是这样哒: 让你输出每个人的停止位置坐标. ①将x轴上初始 ...

  9. 【推导】【贪心】Codeforces Round #431 (Div. 1) A. From Y to Y

    题意:让你构造一个只包含小写字母的可重集,每次可以取两个元素,将它们合并,合并的代价是这两个元素各自的从‘a’到‘z’出现的次数之积的和. 给你K,你构造的可重集必须满足将所有元素合而为一以后,所消耗 ...

随机推荐

  1. C# 多线程、控制线程数提高循环输出效率

    C#多线程及控制线程数量,对for循环输出效率. 虽然输出不规律,但是效率明显提高. 思路: 如果要删除1000条数据,只使用for循环,则一个接着一个输出.所以,把1000条数据分成seed段,每段 ...

  2. python基础-私有变量和方法

    如果要让内部属性不被外部访问,可以把属性的名称前加上两个下划线__,在Python中,实例的变量名如果以__开头,就变成了一个私有变量(private),只有内部可以访问,外部不能访问 __priva ...

  3. ACM学习历程——UVA127 "Accordian" Patience(栈, 链表)

    Description  ``Accordian'' Patience  You are to simulate the playing of games of ``Accordian'' patie ...

  4. bzoj 4514: 数字配对

    题目大意 自己看 题解 我们打表观察规律发现一定能构成一张二分图 也就是不存在奇环 所以我们一般保证费用非负的最大流即可. #include <cstdio> #include <c ...

  5. 【C++基础】重载,覆盖,隐藏

    函数签名的概念 函数签名主要包括1.函数名:2.参数列表(参数的个数.数据类型和顺序):但是注意,C++官方定义中函数签名不包括返回值!! 1.重载 函数重载是指在同一作用域内,可以有一组具有相同函数 ...

  6. JavaScript中的eval()函数详解

    和其他很多解释性语言一样,JavaScript同样可以解释运行由JavaScript源代码组成的字符串,并产生一个值.JavaScript通过全局函数eval()来完成这个工作     eval(“1 ...

  7. Block Change Tracking (块改变跟踪)

    理论背景:Block ChangeTracking 是Oracle 10g里推出的特性. Block change tracking 会记录data file里每个block的update 信息,这些 ...

  8. win7 64位搭建Mantis 缺陷管理系统(2)

    建立Bug数据库 1. 右键Windows托盘的图标,选择“Local Web”,(或者在IE地址中输入“http://127.0.0.1/”)可看到如下页面: 2. 点击选择“mantis”,进入页 ...

  9. hdu水仙花

    水仙花数 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submission ...

  10. Tomcat的安装及使用

    下面是我搭建Tomcat的过程,记录一下 下载地址:http://tomcat.apache.org/  我下载的是8.5.30版本 安装 下载完成后解压到D盘 (配置变量的的教程网上大把随便搜) 1 ...