Codeforces 961 D Pair Of Line

You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct.

You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?

Input

The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given.

Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.

Output

If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.

Examples

Input

Copy

5
0 0
0 1
1 1
1 -1
2 2

Output

Copy

YES

Input

Copy

5
0 0
1 0
2 1
1 1
2 3

Output

Copy

NO

Note

In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.

 题意:

给出你n个点,让你判断这些点是否都在两条直线上

解决思路:

我们可以挑出前三个点,这三个点的情况有两种,其一是三点共线,否则就是三点两点共线另一点不在该条线上。我们的思路是先确定其中的一条直线,如果前三个点三点共线的话任意拿出其中两个点自然可以确定一条直线,至于另外一种情况,我们也可以枚举任意两点共线的所有情况,有一个能满足要求就行。确定一条直线之后将其他的点都枚举一遍,和这条直线共线的不管,把不共线的挑出来,然后判断这些点是否共线。

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

typedef long long ll;
const int maxn = 100010;
int n;

struct point{
	ll x, y;
}poi[maxn];

bool judge(int a, int b, int c)
{
	if((poi[a].y - poi[b].y) * (poi[c].x - poi[b].x) == (poi[a].x - poi[b].x) * (poi[c].y - poi[b].y))
		return true;
	return false;
}

bool slove(int a, int b)
{
	int id[maxn], top = 0;
	for(int i = 6 - a - b; i <= n; ++ i)
	{
		if(i == a || i == b)
			continue;
		if(!judge(a, b, i))
		{
			id[top++] = i;
		}
	}
	if(top <= 2)
		return true;
	for(int i = 2; i < top; ++ i)
	{
		if(!judge(id[0], id[1], id[i]))
			return false;
	}
	return true;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	cin >> n;
	for(int i = 1; i <= n; ++ i)
	{
		cin >> poi[i].x >> poi[i].y;
	}
	if(n <= 4)
	{
		cout << "YES" << endl;
		return 0;
	}
	if(slove(1, 2) || slove(1, 3) || slove(2, 3))
		cout << "YES" << endl;
	else 
		cout << "NO" << endl;
	return  0;
}

猜你喜欢

转载自blog.csdn.net/aqa2037299560/article/details/83986539