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. iframe与父窗口之间数据互相获取

    Js/Jquery获取iframe中的元素 博客分类: jquery javascript jquery  在web开发中,经常会用到iframe,难免会碰到需要在父窗口中使用iframe中的元素.或 ...

  2. 如何修改Eclipse中的快捷键

    首先打开Eclipse,Windows->Preferences ↓ 进入Preferences界面后,选择General->Keys ↓ 接下来你就会看到: 接下来点击OK就可以生效了.

  3. linux中环境变量的用法

    Linux操作系统下三种配置环境变量的方法[转] 在linux下做开发首先就是需要配置环境变量,下面以配置java环境变量为例介绍三种配置环境变量的方法. 1.修改/etc/profile文件 如果你 ...

  4. 通过调节坐标进行jfree图的放大缩小

    http://blog.csdn.net/lt1983lt/article/details/5665085 import Java.awt.BorderLayout;import java.awt.C ...

  5. QtGstreamer 编译

    一  安装依赖项 1 安装cmake hdhuang@hdh-UBT:~/gstreamer/qt-gstreamer-0.10.2/build$ sudo apt-get install cmake ...

  6. INSPIRED启示录 读书笔记 - 第23章 改进现有产品

    不是一味地添加功能 改进产品不是简单地满足个别用户的要求,也不能对用户调查的结果照单全收.能提高指标的功能才是关注的重点.应该找准方向,分析关键指标,有针对性地改进产品

  7. 基于matlab的边缘提取方法的比较

    1.Matlab简述 Matlab是国际上最流行的科学与工程计算的软件工具,它起源于矩阵运算,已经发展成一种高度集成的计算机语言.有人称它为“第四代”计算机语言,它提供了强大的科学运算.灵活的程序设计 ...

  8. Android编译系统简要介绍【转】

    本文转载自:http://blog.csdn.net/luoshengyang/article/details/18466779 在Android源码环境中,我们开发好一个模块后,再写一个Androi ...

  9. Introduction to vSphere Integrated Containers

    vSphere Integrated Containers enables IT teams to seamlessly run traditional workloads and container ...

  10. python安装包

    1. python常用包下载地址:http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy numpy包下载地址:https://pypi.python.org ...