Codeforces Round #431 (Div. 2) B

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 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 还有其他细节自己判断一下

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 double x[1234];
 4 set<double>Se;
 5 double ans;
 6 int main(){
 7     int n;
 8     int flag=0;
 9     cin>>n;
10     cin>>x[1];
11     cin>>x[2];
12     ans=x[2]-x[1];
13     for(int i=3;i<=n;i++){
14         cin>>x[i];
15         if(x[i]-x[i-1]!=ans){
16             flag=1;
17         }
18     }
19     if(x[3]-x[2]!=ans){
20         int flag3=0;
21         double cnt=x[3]-x[2];
22         for(int i=4;i<=n;i++){
23             if(x[i]-x[i-1]!=cnt){
24                 flag3=1;
25             }
26         }
27         if(flag3==0){
28             cout<<"Yes"<<endl;
29             return 0;
30         }
31     }
32     for(int i=1;i<=n;i++){
33         Se.insert(x[i]);
34     }
35     if(Se.size()==1){
36         cout<<"No"<<endl;
37         return 0;
38     }
39     if(Se.size()==2){
40         cout<<"Yes"<<endl;
41         return 0;
42     }
43     if(flag==0){
44         cout<<"No"<<endl;
45         return 0;
46     }else{
47         map<int,int>Mp;
48         double lv;
49         Mp[1]=1;
50         for(int i=2;i<=n;i++){
51             Mp.clear();
52             Mp[i]=1;
53             lv=(x[i]-x[1])/(i-1)*1.0;
54           //  cout<<lv<<" "<<i<<endl;
55             for(int j=2;j<=n;j++){
56                 if(Mp[j]) continue;
57                 //cout<<(x[j]-x[1])/(j-1)<<" "<<j<<endl;
58                 if((x[j]-x[1])/(j-1)==lv){
59                     Mp[j]=1;
60                 }
61             }
62             int x1;
63             for(int j=2;j<=n;j++){
64                 if(Mp[j]==0){
65                     x1=j;
66                     Mp[j]=1;
67                     break;
68                 }
69             }
70           //  cout<<x1<<endl;
71             int flag1=0;
72             for(int j=2;j<=n;j++){
73                 if(Mp[j]==0){
74                 //    cout<<(x[j]-x[x1])/(j-x1)<<"B"<<x1<<" "<<j<<endl;
75                     if((x[j]-x[x1])/(j-x1)!=lv){
76                         flag1=1;
77                     }
78                 }
79             }
80             if(flag1==0){
81                 cout<<"Yes"<<endl;
82                 return 0;
83             }
84         }
85     }
86     cout<<"No"<<endl;
87     return 0;
88 }
时间: 2024-10-05 05:07:57

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

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

给你一个这样的图,那些点是舞者,他们每个人会在原地待ti时间之后,以每秒1m的速度向前移动,到边界以后停止.只不过有时候会碰撞,碰撞之后的转向是这样哒: 让你输出每个人的停止位置坐标. ①将x轴上初始坐标记为(pi,0),y轴上的初始坐标记为(0,pi).只有pi-ti相同的才有可能发生碰撞.于是可以按照这一点将人划分为很多组,不同组之间绝对不会互相影响. ②假设一组内每个人都不会发生碰撞,那么所有的路线交叉点都是碰撞点.所以碰撞次数可能达到n^2次,暴力不可行. ③对于一组内,形成了一个网格图

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 ever break? Given an integer sequence a1, a2, ..., an of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegmen

Codeforces Round #431 (Div. 2) C

From beginning till end, this message has been waiting to be conveyed. For a given unordered multiset of n lowercase English letters ("multi" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat

Codeforces Round #431 (Div. 2) A

Where do odds begin, and where do they end? Where does hope emerge, and will they ever break? Given an integer sequence a1, a2, ..., an of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of w

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

题意:让你构造一个只包含小写字母的可重集,每次可以取两个元素,将它们合并,合并的代价是这两个元素各自的从'a'到'z'出现的次数之积的和. 给你K,你构造的可重集必须满足将所有元素合而为一以后,所消耗的最小代价恰好为K. 考虑只包含一种类字母的消耗代价,以a为例: a 0 aa 1 aaa 3 aaa 6 aaaa 10 aaaaa 15 ... ... 而且如果再其上任意叠加别的字母的话,是互不干涉的.于是可以贪心地从K中依次减去最大的一个上表中的数,输出那么多'a',然后下一次换成'b',如

Codeforces Round #431 Div. 1

A:显然每种字符的代价互不相关,dp并打表可得合并i个字符的最小代价是i*(i-1)/2.然后直接贪心分配每个字符即可.因为每次分配都将剩余代价降到了根号级别所以字符数量是足够的. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std;

Codeforces Round #247 (Div. 2) ABC

Codeforces Round #247 (Div. 2) http://codeforces.com/contest/431 代码均已投放:https://github.com/illuz/WayToACM/tree/master/CodeForces/431 A - Black Square 题目地址 题意: Jury玩别踩白块,游戏中有四个区域,Jury点每个区域要消耗ai的卡路里,给出踩白块的序列,问要消耗多少卡路里. 分析: 模拟水题.. 代码: /* * Author: illuz

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿