A - Tell Your World

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

首先数据范围非常的小,我们可以考虑这个题应该是一个模拟题,然后我们如何模拟呢,我们可以分情况讨论,最后的结果有两种可能,一种是一条直线有一些点,另外一条直线有一些点。另外一种可能是一条直线有一个点,另外一条直线有一些点。一条直线的斜率可以通过两个点确定,所以我们枚举这两个点,拿第一个点和后面的点求出这个直线的斜率,然后判断后面的点,如果后面的点和第一个点求得的斜率和一开始的是一样的,那么就标记一下。然后我们找到前两个没有被标记过的点,求出这两个点的斜率,然后再看后面的没有被标记过的点,和后面的点如果求得的斜率相等的话,也标记,最后看是否所有点都被标记过,这边还得注意一下,我们求得第一个斜率后,我们要判断此时是否只有一个点没有被标记,如果是的话就说明符合条件。在循环结束后,我们还得判断是否有第一个点是单独的,其余的点可以构成一个直线的情况

当然还得判断所有的点不能在一个直线上,并且两条直线的斜率应该相等

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
//#include <ext/rope>
#include <bits/stdc++.h> 

using namespace std;

#define gt(x) x = read()
#define int  long long
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define x first
//#define y second

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0}; 

//typedef __int128 INT;
typedef pair<double, int> PDI;
typedef pair<int, int> PII;
typedef unsigned long long ULL;

inline int read(int out = 0)
{
    char c;
    while((c=getchar()) < 48 || c > 57);
    while(c >= 48 && c <= 57) out=out*10+c-48,c=getchar();
    return out; 
}

const int N = 1010;
const int M = 4 * N;
const int mod = 1e4 + 7;
const int PP = 13331;
const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-10;
const double PI = acos(-1);

double a[N];
bool st[N];

signed main(){
	int n;
	while(~scanf("%lld",&n)){
		bool flag = false;
		for (int i = 1; i <= n; i ++)   scanf("%lf", &a[i]);
		
		for (int i = 2; i <= n; i ++){
			memset(st, 0, sizeof st);
			st[1] = true;
			double k = (double)(a[i] - a[1]) / (double)(i - 1);
			
			for (int j = 2; j <= n; j ++){
				if ((double)(a[j] - a[1]) / (double)(j - 1) == k)    st[j] = true;
			}
			
			int cnt = 0;
			for (int j = 1; j <= n; j ++){
				if (st[j])   cnt ++;
			}
			if (cnt == n - 1)     flag = true;
			else if (cnt != n){
				int j = 1;
				while(st[j])   j ++;
				st[j] = true;
				
				int h = j + 1;
				while(st[h])   h ++;
				st[h] = true;
				
				double kk = (double)(a[h] - a[j]) / (double)(h - j);
				if (kk != k)   continue;
				
				for (int l = h + 1; l <= n; l ++){
					if (!st[l]){
						if ((double)(a[l] - a[h]) / (double)(l - h) == kk)
						  st[l] = true;
					}
				}
				
				int p = 0;
				for (int j = 1; j <= n; j ++){
					if (!st[j]){
						p = 1;
						break;
					}
				}
				
				if (!p)   flag = true;
			}
			
			if (flag)   break;
		}
		
		double k = (double)(a[3] - a[2]) / (double)(1.0);
		
		int i;
		for (i = 4; i <= n; i ++){
			if ((double)(a[i] - a[2]) / (i - 2) != k)    break;	
		}
		
		if ((double)(a[2] - a[1]) / 1.0 != k && i > n)   flag = true;
		
		if (flag)    cout << "Yes" << endl;
		else  cout << "No" << endl;	
	}
	
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值