Codeforces 961 D Pair Of Lines
题目描述
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.
输入输出样例
5
0 0
0 1
1 1
1 -1
2 2
YES
5
0 0
1 0
2 1
1 1
2 3
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的更多相关文章
- 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 ...
- 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 ...
- 【Educational Codeforces Round 41 (Rated for Div. 2) D】Pair Of Lines
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果点的个数<=3 那么直接输出有解. 否则. 假设1,2最后会在一条直线上,则把这条直线上的点都删掉. 看看剩余的点是否在同 ...
- D. Pair Of Lines( Educational Codeforces Round 41 (Rated for Div. 2))
#include <vector> #include <iostream> #include <algorithm> using namespace std; ty ...
- Educational Codeforces Round 41 D. Pair Of Lines(961D)
[题意概述] 给出平面上的10W个点,要求判断这些点能否被两条直线穿过,即一个点至少在一条直线上. [题解] 思路很快可以想到.取3个不共线的点,它们形成一个三角形:如果有解,其中的一条直线一定与三角 ...
- Codeforces 395 D.Pair of Numbers
D. Pair of Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 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 ...
- 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& ...
- Codeforces 961 E Tufurama
Discription One day Polycarp decided to rewatch his absolute favourite episode of well-known TV seri ...
随机推荐
- LeetCode 数组中的第K个最大元素
在未排序的数组中找到第 k 个最大的元素.请注意,你需要找的是数组排序后的第 k 个最大的元素,而不是第 k 个不同的元素. 示例 1: 输入: [3,2,1,5,6,4] 和 k = 2 输出: 5 ...
- (59)zabbix拓扑图展示链路状况Link indicators
Link indicators介绍 上一篇已经了解了如何配置zabbix map,也提到了如何连接两个map元素,这节我们来讲两个map元素之间的链路指示配置. 我们需要在链路上配置trigger,如 ...
- Git学习——提交BUG
git stash 可以把当前工作区的修改存储起来,此时可以查看工作区是干净的.这时可以切换到别的分支去处理BUG.等BUG处理好之后,回到该分支,恢复工作区.通过: git stash list 查 ...
- perl5中锚位修饰符\A \z \Z 和perl4中^(开头)和$(结尾)的区别
习惯使用perl4的开发者总是用^表示字符串开头锚位,用$表示字符串结尾锚位,比如\^https://\ 将会匹配所有以https://开头的字符串,同样,\.bmp$\将会匹配所有以.bmp结尾的字 ...
- SVN 如何提交 SO 库文件
今天提交代码时候发现,svn add 还是 svn st 均查看不到想要提交的 so 文件. 后来才知道原来是配置文件出了问题,把so文件的提交给屏蔽掉了. 修改步骤如下: 1.Ubuntu 系统,点 ...
- Linux Shell脚本教程:30分钟玩转Shell脚本编程
http://c.biancheng.net/cpp/shell/ Linux在线体验: http://compileonline.com/ Linux命令查询: http://man.linuxde ...
- 纯干货!live2d动画制作简述以及踩坑
本文来自网易云社区,转载务必请注明出处. 1. 概述 live2d是由日本Cybernoids公司开发,通过扭曲像素位置营造伪3d空间感的二维动画软件.官网下载安装包直接安装可以得到两种软件,分别是C ...
- iphone丢了以后发现关机了怎么办?
有好几个办法都可以尝试一下: 1. "ICCID法",但目前这个办法只能寻找苹果iPhone手机,而对于安卓手机,则不能采取相同的方法进行寻找.之所以能采取该方法寻找苹果 iPho ...
- Leetcode 407.接雨水
接雨水 给定一个 m x n 的矩阵,其中的值均为正整数,代表二维高度图每个单元的高度,请计算图中形状最多能接多少体积的雨水. 说明: m 和 n 都是小于110的整数.每一个单位的高度都大于0 且小 ...
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)
昨晚打得小号,虽然很菜,可是还是涨了些rating A. Arpa and a research in Mexican wave time limit per test 1 second memory ...