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. Python 1 的数据类型

    Python3 中有六个标准的数据类型: Number(数字)String(字符串)List(列表)Tuple(元组)Sets(集合)Dictionary(字典) 1.Number(数字) pytho ...

  2. iOS Xcode 8 快捷键 (注释 失效 处理)

    在升级后,好用的VVDocumment 插件不能用了.(但是苹果这次内置了好多好用的插件,也有自己的注释功能了 AddDocumentation) 上网上有查到 传播很广泛的一条信息 "这个 ...

  3. vagrant搭建

    1.在官网下载对应的vagrant版本 https://www.vagrantup.com/downloads.html (下载最新版本) https://releases.hashicorp.com ...

  4. python局部变量引用问题

    a = [1, 2] b = 'Immutable' def test(): # global b print(a) a.append('asd') b = b + 'asd' # 当只是引用变量b的 ...

  5. java resources 红叉 Cannot change version of project facet Dynamic Web Module to 2.5

    在使用maven导入项目的时候,markers提示Cannot change version of project facet Dynamic Web Module to 2.5,不能将工程转换为2. ...

  6. setfacl设置特定目录的权限

    现有一目录是虚拟机和linux共享的,但是每次程序调用新建的文件都发现没有权限. 于是指定特定目录及其子目录下新建的文件或目录对于用户qhfz都有读写执行的权限 -R表示递归 -m表示设置文件acl规 ...

  7. EasyUI学习

    1.基础知识: 1)Parser解析器: div指定了class后能有效果是因为开始时文档时加载DOM但是一些由js动态生成的指定了class的div没有被解析此时就需要手动解析了 js动态生成的指定 ...

  8. 基于主主复制的mysql双机热备+keepalived实现高可用性

  9. 2017 GDS 全球域名大会7月7日举行

    2017年域名行业历经产业波澜,引发域名圈内对域名价值衍生及商业模式的探索.如今无论域名注册商.域名交易平台.域名拍卖平台都在寻找更好的商业模式,开启域名行业新航向. 7月,在中国域名之都厦门将掀起一 ...

  10. 数据结构习题 线段树&树状数组

    说明:这是去年写了一半的东西,一直存在草稿箱里,今天整理东西的时候才发现,还是把它发表出来吧.. 以下所有题目来自Lrj的<训练指南> LA 2191 单点修改,区间和  Fenwick直 ...