CodeForces - 961D:Pair Of Lines (几何,问两条直线是否可以覆盖所有点)
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
5
0 0
0 1
1 1
1 -1
2 2
YES
5
0 0
1 0
2 1
1 1
2 3
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 (几何,问两条直线是否可以覆盖所有点)的更多相关文章
- POJ1269:Intersecting Lines(判断两条直线的关系)
题目:POJ1269 题意:给你两条直线的坐标,判断两条直线是否共线.平行.相交,若相交,求出交点. 思路:直线相交判断.如果相交求交点. 首先先判断是否共线,之后判断是否平行,如果都不是就直接求交点 ...
- 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 ...
- 判断两条直线的位置关系 POJ 1269 Intersecting Lines
两条直线可能有三种关系:1.共线 2.平行(不包括共线) 3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...
- poj 1269(两条直线交点)
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13481 Accepted: 59 ...
- 求空间内两条直线的最近距离以及最近点的坐标(C++)
关键词:空间几何 用途:总有地方会用到吧 文章类型:C++函数展示 @Author:VShawn(singlex@foxmail.com) @Date:2016-11-19 @Lab: CvLab20 ...
- 2018-7-31-C#-判断两条直线距离
title author date CreateTime categories C# 判断两条直线距离 lindexi 2018-07-31 14:38:13 +0800 2018-05-08 10: ...
- 两条直线(蓝桥杯)二分枚举+RMQ
算法提高 两条直线 时间限制:1.0s 内存限制:256.0MB 问题描述 给定平面上n个点. 求两条直线,这两条直线互相垂直,而且它们与x轴的夹角为45度,并且n个点中离这两条 ...
- 计算两条直线的交点(C#)
PS:从其他地方看到的源码是有问题的.下面是修正后的 /// <summary> /// 计算两条直线的交点 /// </summary> /// <param name ...
- C++ 根据两点式方法求直线并求两条直线的交点
Line.h #pragma once //Microsoft Visual Studio 2015 Enterprise //根据两点式方法求直线,并求两条直线的交点 #include"B ...
随机推荐
- 每天一个Linux命令(41)iostat命令
iostat是I/O statistics(输入/输出统计)的缩写,对系统的磁盘操作活动进行监视.它的特点是汇报磁盘活动统计情况,同时也会汇报出CPU使用情况. (1)用法: ...
- Spring session共享(使用redis)
SpringBoot+Redis实现HttpSession共享 前提:需要使用redis做session存储 一.效果演练(这里使用SpringBoot工程,Spring同理) 1.一个工程使用两个端 ...
- MongoDB命令语法小用
using System; using System.Collections.Generic; using System.Linq; using System.Text; using MongoDB; ...
- 主攻ASP.NET.4.5.1 MVC5.0之重生:在项目中使用zTree jQuery 树插件
效果图和json格式 Controllers代码 using HR.Models; using HR.Models.Repository; /***************************** ...
- 跨平台移动开发 Xuijs超轻量级的框架Style CSS属性用法
PhoneGap里面推荐使用的超轻量级的框架 Style CSS属性用法 设置css属性:setstyle 通过ID设置css属性 x$('#top1').setStyle('color', '#DB ...
- python:格式化输出 str.format()
官网说明:https://docs.python.org/2/library/string.html#formatstrings python的格式输出有两种方法: 1.“ %s”.(variant) ...
- DATE_FORMAT() 函数用于以不同的格式显示日期/时间数据。
DATE_FORMAT(date,format) format参数的格式有 %a 缩写星期名 %b 缩写月名 %c 月,数值 %D 带有英文前缀的月中的天 %d 月的天,数值(00-31) %e 月的 ...
- 关于Json如何转换成对象及获值问题!
var result = eval('('+result+')'); result为Json 转换成var result对象,可以 if(result.success){ window.locatio ...
- php如何查看扩展是否开启
php如何查看扩展是否开启 一.总结 一句话总结:php -m 1.查看php已安装扩展命令 ? php -m 2.phpinfo();这是最常用的方法,但那么多扩展一时还真不太好找.? 3.exte ...
- vs plug
工欲善其事,必先利其器.尽管visual studio本身已经非常强大,但优秀的插件仍然可以帮开发者大大提高效率,以下是牛牛非常喜欢的vs插件. 1.Indent Guides 绝对是必须的,有了这些 ...