1. 程式人生 > >Codeforces 961 D Pair Of Line

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;
}