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. Shell读取文件内容【转】

    while read wOne wTwo wThreedo    [ -z $wOne ] && continue           #测试此行内容是否为空    xxx=$wOne ...

  2. 用nexus搭建自己的maven私有仓库

    用nexus搭建自己的maven私有仓库  刚安装nexus时,nexus启动失败,启动不到1分钟,自动停止.后来查找到了原因: Java 6 Support EOLOracle's support ...

  3. [RTOS]--uCOS、FreeRTOS、RTThread、RTX等RTOS的对比之特点

    本篇博客就来细数这几个RTOS的特点.   以下内容均来自官方网站或者官方手册Feature的Google翻译的加了我的一些调整,没有任何主观成分. 1. FreeRTOS   FreeRTOS是专为 ...

  4. 前端PHP Session的实例

    登陆例子:(请注意一定要自己敲一遍,不要CV大法) 首先上一下成果图,激起同学们写的欲望,登录页如下:  点击登陆之后如下: 说明哦了,么问题.接下来自己实现一下. 首先数据库信息: 新建一个名为 l ...

  5. 算法导论笔记——第二十章 van Emde Boas树

    当关键字是有界范围内的整数时,能够规避Ω(lglgn)下界的限制,那么在类似的场景下,我们应弄清楚o(lgn)时间内是否可以完成优先队列的每个操作.在本章中,我们将看到:van Emde Boas树支 ...

  6. UI 界面:技术决定一切

    转自:http://www.cnblogs.com/NEOCSL/archive/2012/12/10/2811153.html 在我看来,肖恩帕克不仅仅是一位技术天才和远见卓识的移动互联网领域先锋. ...

  7. caffe solver

    caffe solver https://groups.google.com/forum/#!topic/caffe-users/mUIi42aKWHQ https://github.com/BVLC ...

  8. [poj1986]Distance Queries(LCA)

    解题关键:LCA模板题 复杂度:$O(n\log n)$ #pragma comment(linker, "/STACK:1024000000,1024000000") #incl ...

  9. Inno Setup整理

    1.如何使inno setup添加快捷方式默认选中 在[Tasks]段,有 Flags:unchecked改成 Flags: checkablealone; 即可 完整代码示例: [Tasks] Na ...

  10. 《SpringBoot揭秘 快速构建微服务体系》读后感(二)

    最简单的springBoot应用 package com.louis.test; import org.springframework.boot.SpringApplication; import o ...