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

题意:给定N个点,问是否可以用一条或者两条直线覆盖所有点。

思路:如果所有点已经在一条直线上,成立。 否则找不共线的三个点,那么其中一条线必定的其中一条,然后验证即可。

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
using namespace std;
const int maxn=;
int N,A,B,C,x[maxn],y[maxn],vis[maxn],num;
bool line(int a,int b,int c){
if(x[a]==x[b]&&x[a]==x[c]) return true;
if(y[a]==y[b]&&y[a]==y[c]) return true;
if((ll)(1LL*x[a]-x[b])*(y[b]-y[c])-(1LL*y[a]-y[b])*(x[b]-x[c])==) return true;
return false;
}
bool find()
{
rep(i,,N)
if(!line(,,i)) {
C=i; return true;
} return false;
}
bool check(int a,int b)
{
int A=-,B=-;
rep(i,,N) vis[i]=;num=;
rep(i,,N)
if(line(a,b,i)) vis[i]=,num++;
else { if(A==-) A=i; else if(B==-) B=i; }
if(num==N||num==N-||num==N-) return true;
rep(i,,N) if(!vis[i]) if(!line(A,B,i)) return false;
return true;
}
int main()
{
scanf("%d",&N);
rep(i,,N) scanf("%d%d",&x[i],&y[i]);
if(!find()) return puts("YES"),;
if(check(,)) return puts("YES"),;
if(check(,C)) return puts("YES"),;
if(check(,C)) return puts("YES"),;
puts("NO");
return ;
}

CodeForces - 961D:Pair Of Lines (几何,问两条直线是否可以覆盖所有点)的更多相关文章

  1. POJ1269:Intersecting Lines(判断两条直线的关系)

    题目:POJ1269 题意:给你两条直线的坐标,判断两条直线是否共线.平行.相交,若相交,求出交点. 思路:直线相交判断.如果相交求交点. 首先先判断是否共线,之后判断是否平行,如果都不是就直接求交点 ...

  2. Educational Codeforces Round 41 (Rated for Div. 2) D. Pair Of Lines (几何,随机)

    D. Pair Of Lines time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  3. 判断两条直线的位置关系 POJ 1269 Intersecting Lines

    两条直线可能有三种关系:1.共线     2.平行(不包括共线)    3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...

  4. poj 1269(两条直线交点)

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13481   Accepted: 59 ...

  5. 求空间内两条直线的最近距离以及最近点的坐标(C++)

    关键词:空间几何 用途:总有地方会用到吧 文章类型:C++函数展示 @Author:VShawn(singlex@foxmail.com) @Date:2016-11-19 @Lab: CvLab20 ...

  6. 2018-7-31-C#-判断两条直线距离

    title author date CreateTime categories C# 判断两条直线距离 lindexi 2018-07-31 14:38:13 +0800 2018-05-08 10: ...

  7. 两条直线(蓝桥杯)二分枚举+RMQ

    算法提高 两条直线   时间限制:1.0s   内存限制:256.0MB        问题描述 给定平面上n个点. 求两条直线,这两条直线互相垂直,而且它们与x轴的夹角为45度,并且n个点中离这两条 ...

  8. 计算两条直线的交点(C#)

    PS:从其他地方看到的源码是有问题的.下面是修正后的 /// <summary> /// 计算两条直线的交点 /// </summary> /// <param name ...

  9. C++ 根据两点式方法求直线并求两条直线的交点

    Line.h #pragma once //Microsoft Visual Studio 2015 Enterprise //根据两点式方法求直线,并求两条直线的交点 #include"B ...

随机推荐

  1. JAVA中遍历Map和Set方法,取出map中所有的key

    Java遍历Set集合 1.迭代器遍历: Set<String> set = new HashSet<String>(); Iterator<String> it ...

  2. GIS学习和开发的在线资源

    1.OpenGIS Consortium标准,http://www.opengeospatial.org.著名的OGC标准是每个GIS开发者最后都不得不学习的,或深或浅. 2.SharpMap,Pro ...

  3.  Link 

    GNU/Linux, Bash, C, PHP, Perl, JavaScript, Vim, Git http://blog.sanctum.geek.nz/about   中文數學詞典 http: ...

  4. Python学习进程(14)异常处理

        本节介绍Python进行异常处理的方式,异常处理机制可以帮助我们调试python程序.     (1)异常的简介:     异常即是一个事件,该事件会在程序执行过程中发生,影响了程序的正常执行 ...

  5. jsp导出

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  6. Linux文件系统管理 常见命令df、du、fsck、dumpe2fs

    概述 Linux文件系统管理 常见命令df.du.fsck.dumpe2fs. 文件系统查看命令:df 通过 df 命令可以査看已经挂载的文件系统的信息包括设备文件名.文件系统总大小.已经使用的大小. ...

  7. Linux权限管理 文件特殊权限

    概述 除了我们前面介绍的rwx权限外,Linux中还有另外三种特殊权限:SUID,SGID,SBIT   权限    执行条件 执行示例 SUID s出现在文件所有者的x权限上. 1. SUID只能用 ...

  8. Django-虚拟环境设置

    Django 虚拟环境virtualenv virtualenv是用来处理多个用python语言进行开发的项目,在同一台机器上部署,不同项目依赖不同第三方库版本所造成的问题. 打个比方,现在你机器上要 ...

  9. shell中的$()、${}、$(())、(())

    $( ) 与 ` ` (反引号)在 bash shell 中,$( ) 与 ` ` (反引号) 都是用来做命令替换用(command substitution)的. 所谓的命令替换与我们第五章学过的变 ...

  10. 记录python面试题

    闲来无事,记录一下曾经以及深刻的面试题 记录一下我记忆比较深的面试题,以后若用到python相关还能细细把玩 搜狐面试题: 一.写一个缓存优化策略 解答:这个题主要考察对lru_cache的理解,所以 ...