题目描述

You are given nn 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?

输入输出格式

输入格式:

The first line contains one integer nn (1<=n<=10^{5})(1<=n<=105) — the number of points you are given.

Then nn lines follow, each line containing two integers x_{i}xi​ and y_{i}yi​ (|x_{i}|,|y_{i}|<=10^{9})(∣xi​∣,∣yi​∣<=109) — coordinates of ii -th point. All nn points are distinct.

输出格式:

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.

输入输出样例

输入样例#1:

5
0 0
0 1
1 1
1 -1
2 2
输出样例#1:

YES
输入样例#2:

5
0 0
1 0
2 1
1 1
2 3
输出样例#2:

NO

说明

In the first example it is possible to draw two lines, the one containing the points 11 , 33 and 55 , and another one containing two remaining points.

一个很显然的性质是,任意三个点中至少有两个在同一条直线上。

也就是说,在一个可行的方案中,至少有一条线是经过 点1-点2 或者 点2-点3 或者 点1-点3 构成的直线的,所以我们直接做就行了。。。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=100005;
int px[maxn],py[maxn],n;
int dx,dy,now;
bool tag[maxn]; inline bool check(int x,int y){
memset(tag,0,sizeof(tag));
tag[x]=tag[y]=1,now=x;
dx=px[x]-px[y],dy=py[x]-py[y]; for(int i=1;i<=n;i++) if(!tag[i])
if(dx*(ll)(py[i]-py[now])==dy*(ll)(px[i]-px[now])) tag[i]=1; bool flag=1;
for(int i=1;i<=n;i++) if(!tag[i]){
for(int j=i+1;j<=n;j++) if(!tag[j]){
dx=px[j]-px[i],dy=py[j]-py[i],now=i;
for(int l=j+1;l<=n;l++) if(!tag[l]&&dx*(ll)(py[l]-py[now])!=dy*(ll)(px[l]-px[now])) flag=0;
break;
}
break;
} return flag;
} inline void solve(){
if(n<=4){
puts("YES");
return;
} if(check(1,2)||check(1,3)||check(2,3)) puts("YES");
else puts("NO");
} int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d%d",px+i,py+i);
solve();
return 0;
}

  

Codeforces 961 D Pair Of Lines的更多相关文章

  1. CodeForces - 961D:Pair Of Lines (几何,问两条直线是否可以覆盖所有点)

    You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordin ...

  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. 【Educational Codeforces Round 41 (Rated for Div. 2) D】Pair Of Lines

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果点的个数<=3 那么直接输出有解. 否则. 假设1,2最后会在一条直线上,则把这条直线上的点都删掉. 看看剩余的点是否在同 ...

  4. D. Pair Of Lines( Educational Codeforces Round 41 (Rated for Div. 2))

    #include <vector> #include <iostream> #include <algorithm> using namespace std; ty ...

  5. Educational Codeforces Round 41 D. Pair Of Lines(961D)

    [题意概述] 给出平面上的10W个点,要求判断这些点能否被两条直线穿过,即一个点至少在一条直线上. [题解] 思路很快可以想到.取3个不共线的点,它们形成一个三角形:如果有解,其中的一条直线一定与三角 ...

  6. Codeforces 395 D.Pair of Numbers

    D. Pair of Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. CF961D Pair Of Lines

    题目描述 You are given n n n points on Cartesian plane. Every point is a lattice point (i. e. both of it ...

  8. Codeforces 1023 B.Pair of Toys (Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Fi)

    B. Pair of Toys 智障题目(嘤嘤嘤~) 代码: 1 //B 2 #include<iostream> 3 #include<cstdio> 4 #include& ...

  9. Codeforces 961 E Tufurama

    Discription One day Polycarp decided to rewatch his absolute favourite episode of well-known TV seri ...

随机推荐

  1. x220 OS X 10.10.4安装

    变色龙安装过程: 1.使用磁盘助手将按照盘写入独立的磁盘分区(AF格式,就是Apple的HPS格式): 2.安装启动时,用-v -f -x参数,分别为显示信息.重新build系统驱动.安全模式: 3. ...

  2. 高度自适应的bug

    今天在整理之前IFEde作业,发现有个简历的效果好像没实现.于是想把样式改成作业要求的那样. 作业要求是这样的: 右边栏昨晚高度是839px,我想把左边栏做成高度自适应的.但是没成功.现在我把这个问题 ...

  3. DOM事件总结

    1.DOM事件: DOM0: element.onclick=function(){} DOM2: element.addEventListener(‘click’,function(){}) add ...

  4. 【Java_Spring】控制反转IOC(Inversion of Control)

    1. IOC的概念 控制反转IoC(Inversion of Control)是一种设计思想,而DI(依赖注入)是实现IoC的一种方法.在没有使用IOC的程序中,对象间的依赖关系是靠硬编码的方式实现的 ...

  5. verilog behavioral modeling--branch statement

    conditional statement case statement 1. conditional statement     if(expression)         statement_o ...

  6. django第11天(分页器)

    django第11天分页器 分页模块 批量插入数据 book_list = [] #先生成对象 for i in range(100): book = Book(name = 'book%s'%i,p ...

  7. Onenote代码高亮的实现方法

    最终效果图 最终的效果图如下: VBA的编写参考 主要参考的是这篇博客中的思路:如何在Word中排出漂亮的代码 将VBA脚本复制到Word中并设置快捷键 Alt+F11 打开Word中的 VBS,将下 ...

  8. Python开发:面向对象

    Python从设计之初就已经是一门面向对象的语言,正因为如此,在Python中创建一个类和对象是很容易的. 如果你以前没有接触过面向对象的编程语言,那你可能需要先了解一些面向对象语言的一些基本特征,在 ...

  9. python 配置opencv-python 接口

    anaconda2下配置opencv-python 接口,import cv2遇到no cv2 模块问题,解决办法是将cv2.so放到anaconda2/lib/python2.7/site-pack ...

  10. hdu 4251 The Famous ICPC Team Again划分树入门题

    The Famous ICPC Team Again Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...