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进阶(4)_进程与线程 (python并发编程之多进程)

    一.python并发编程之多进程 1.1 multiprocessing模块介绍 由于GIL的存在,python中的多线程其实并不是真正的多线程,如果想要充分地使用多核CPU的资源,在python中大 ...

  2. LDA主题模型三连击-入门/理论/代码

    目录 概况 为什么需要 LDA是什么 LDA的应用 gensim应用 数学原理 预备知识 抽取模型 样本生成 代码编写 本文将从三个方面介绍LDA主题模型--整体概况.数学推导.动手实现. 关于LDA ...

  3. Java访问网络url,获取网页的html代码

    在Java中,Java.net包里面的类是进行网络编程的,其中,java.net.URL类和java.net.URLConection类是编程者方便地利用URL在Internet上进行网络通信.有两种 ...

  4. 020_自己编写的wordcount程序在hadoop上面运行,不使用插件hadoop-eclipse-plugin-1.2.1.jar

    1.Eclipse中无插件运行MP程序 1)在Eclipse中编写MapReduce程序 2)打包成jar包 3)使用FTP工具,上传jar到hadoop 集群环境 4)运行 2.具体步骤 说明:该程 ...

  5. Vuex mapGetters,mapActions

    一.基本用法 1. 初始化并创建一个项目 ? 1 2 3 vue init webpack-simple vuex-demo cd vuex-demo npm install 2. 安装 vuex ? ...

  6. github资源下载速度慢的解决办法

    xx-net:https://github.com/XX-net/XX-Net

  7. ubuntu里设置从串口登录

    1) Create a file called /etc/init/ttyS0.conf containing the following: # ttySAC0 - getty # # This se ...

  8. node拦截器设置

    node的拦截器主要目的是用户登录的时候为用户存了一个session,用户登录后的其他操作都要经过拦截器,对比session的值,并把session的过期时间延长. 拦截器主要是在路由文件routes ...

  9. console.log()方法中%s的作用

    一.console.log("log信息"); 二.console.log("%s","first","second") ...

  10. 20145240《Java程序设计》第七周学习总结

    20145240<Java程序设计>第七周学习总结 教材学习内容总结 12.1认识Lambda语法 12.1.1Lambda语法概览 在java中引入了Lambda的同时,与现有API维持 ...