Pair Of Lines CodeForces - 961D (数学 直线 上的几何)

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
5
0 0
0 1
1 1
1 -1
2 2
Output
YES
Input
5
0 0
1 0
2 1
1 1
2 3
Output
NO
Note

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


题意:输出一个n,下面n行每行一个点,判断是否存在两条直线 能使穿过所有的点;

思路:由于现在不会几何模板,所以就用的数学上的知识的写的;

先假设前三个点不在一条直线上,三个不共线的点确定三条直线,那么要是所有的点想在两条直线上,那么一定是在这三条直线的两条上,但是具体写的时候不是从三条直线中任取两条判断,而是从三条直线上任取一条,把在条直线上的点全部标记,在看看没有被标记的点是不是在一条直线上, 这样判断 就算前三个点在一条直线上也没事,等于这一条直线被判断了三次;具体的看代码;

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long 
#define Max 100010
struct node
{
	ll x,y;
}stu[Max];
ll n;
int book[Max];
int check(int ss,int ee)
{
	int i;
	memset(book,0,sizeof(book));
	for(i = 0;i<n;i++)
	{
		if((stu[ee].x-stu[ss].x)*(stu[i].y-stu[ss].y)==(stu[ee].y-stu[ss].y)*(stu[i].x-stu[ss].x))
			book[i] = 1;  
	}
	
	int a[3];
	int sum  = 0;
	for(i = 0;i<n;i++)
	{
		if(!book[i])
			a[sum++] = i;
		if(sum==2)
			break;
	}
	if(sum<2) return 1;
	for(i = 0;i<n;i++)
	{
		if((stu[a[1]].x-stu[a[0]].x)*(stu[i].y-stu[a[0]].y)==(stu[a[1]].y-stu[a[0]].y)*(stu[i].x-stu[a[0]].x))
			book[i] = 1;  
	}
	for(i = 0;i<n;i++)
	{
		if(!book[i])
			return 0;
	}
	return 1;
}


int main()
{
	ll i,j;
	while(~scanf("%d",&n))
	{
		for(i = 0;i<n;i++)
			scanf("%lld%lld",&stu[i].x,&stu[i].y);
		if(n<=4)
		{
			printf("YES\n");
			continue;
		} 
		if(check(0,1)||check(0,2)||check(1,2))
		{
			printf("YES\n");
		}
		else printf("NO\n");
	}
	return 0;	

} 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值