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 ...
随机推荐
- java设计模式基础 - 解决某一类问题最行之有效的方法,框架是大的设计模式.
一.单例模式(Singleton) 1.单例对象(Singleton)是一种常用的设计模式.在Java应用中,单例对象能保证在一个JVM中,该对象只有一个实例存在.这样的模式有几个好处: 1>某 ...
- 【tarjan 拓扑排序 dp】bzoj1093: [ZJOI2007]最大半连通子图
思维难度不大,关键考代码实现能力.一些细节还是很妙的. Description 一个有向图G=(V,E)称为半连通的(Semi-Connected),如果满足:?u,v∈V,满足u→v或v→u,即对于 ...
- Controller View 模式
参考:https://blog.andrewray.me/the-reactjs-controller-view-pattern/ Flux参考:http://www.cnblogs.com/hell ...
- 二段式fsm
1.推荐在敏感表下的默认状态为X,这样描述的好处有2个: 好处1:仿真易观察bug. 好处2:综合对不定态X的处理是"Don't Care",即任何没有定义的状态寄存器向量都会被忽 ...
- 收集自网络上有关Kali的各种源
更新源总结 #更新源 gedit /etc/apt/sources.list #中科大kali源 deb http://mirrors.ustc.edu.cn/kali kali-rollin ...
- (原)剑指offer之旋转数组
题目描述 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素. 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋 ...
- LeetCode(40) Combination Sum II
题目 Given a collection of candidate numbers (C) and a target number (T), find all unique combinations ...
- 基础训练 Huffuman树
Huffuman树 /*解法一*/ #include<iostream> #include<queue> using namespace std; int main(){ pr ...
- 【LeetCode】Symmetric Tree(对称二叉树)
这道题是LeetCode里的第101道题.是我在学数据结构——二叉树的时候碰见的题. 题目如下: 给定一个二叉树,检查它是否是镜像对称的. 例如,二叉树 [1,2,2,3,4,4,3] 是对称的. 1 ...
- LeetCode答案(python)
1. 两数之和 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用这 ...