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 ...
随机推荐
- Windows10+anaconda,python3.5, 安装glove-python
Windows10+anaconda,python3.5, 安装glove-python安装glove安装之前 Visual C++ 2015 Build Tools开始安装安装glove最近因为一个 ...
- bootstrap下拉菜单(Dropdowns)
本章将重点讲解bootstrap下拉菜单(Dropdowns),下拉菜单是可切换的,是以列表格式显示链接的上下文菜单. <!DOCTYPE html><html><hea ...
- 674. Longest Continuous Increasing Subsequence@python
Given an unsorted array of integers, find the length of longest continuous increasing subsequence (s ...
- CF-1100 E Andrew and Taxi
CF-1100E Andrew and Taxi https://codeforces.com/contest/1100/problem/E 知识点: 二分 判断图中是否有环 题意: 一个有向图,每边 ...
- PAT 乙级 1010
题目 题目地址:PAT 乙级 1010 思路 首先一个问题就是审题不清,导致代码返工了很多次,最后还没写对: 其次对于这道题来说每次输入一组数据之后就可以输出结果,太过机械地想要套用题目给出的输出样例 ...
- ZOJ Monthly, January 2019-Little Sub and Pascal's Triangle
这个题的话,它每行奇数的个数等于该行行号,如果是0开始的,就该数的二进制中的1的个数,设为k,以它作为次数,2k就是了. #include <stdio.h> int main() { i ...
- 编译openwrt_MT7688_hiwooya
参考链接: 无涯论坛地址: http://www.hi-wooya.com/forum.php openwrt官网地址:https://openwrt.org/zh-cn/doc/howto/buil ...
- 递归函数&二分查找
一.递归函数 1)定义 在函数中调用函数本身,就是递归 在python中递归的深度最大为1000,但实际达不到1000 def func(): print("-----func-----&q ...
- vfs_caches_init函数解析
vfs_caches_init函数初始化VFS,下面梳理函数调用流程 start_kernel() -->vfs_caches_init_early(); -->dcache_init_e ...
- Cocos2D 添加 UIView
cocos2d是使用继承于ccnode的结点类型的层.但是我想用一个opengl来绘制,就简单的情况来说必须得加一个uiview.现转载如下: 第一部分:: 使用Cocos2D开发游戏和应用程序的时候 ...