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 ...
随机推荐
- 高度自适应的bug
今天在整理之前IFEde作业,发现有个简历的效果好像没实现.于是想把样式改成作业要求的那样. 作业要求是这样的: 右边栏昨晚高度是839px,我想把左边栏做成高度自适应的.但是没成功.现在我把这个问题 ...
- 前端css学习记录
参考资料:CSS权威指南(第三版)中文版 核心要点: HTML负责标记文档的结构(HyperText Markup Language),结构化语言. CSS 负责表现文档的样式(Cascading S ...
- PAT 乙级 1013
题目 题目地址:PAT 乙级 1013 思路 审题没把范围看清楚,没一次AC 题中m和n都表示第几个素数,范围是10000,所以查询的数组中需要的素数量至少10000,所以需要计算大概2~120000 ...
- 初涉树形dp
算是一个……复习以及进阶? 什么是树形dp 树形dp是一种奇妙的dp…… 它的一个重要拓展是和各种树形的数据结构结合,比如说在trie上.自动机上的dp. 而且有些时候还可以拓展到环加外向树.仙人掌上 ...
- GIMP工具箱的自定义操作
首选项 中还包含工具箱的自定义操作:
- 虚拟dom和diff算法
https://github.com/livoras/blog/issues/13 这里简单记录一些要点和理解: 一个dom元素中有许多属性,操作dom是很耗资源的,而操作自定义的js对象是很高效.所 ...
- Flask 系列之 构建 Swagger UI 风格的 WebAPI
说明 操作系统:Windows 10 Python 版本:3.7x 虚拟环境管理器:virtualenv 代码编辑器:VS Code 实验 环境初始化 # 创建项目目录 mkdir helloworl ...
- linux-命令学习-1
1. cat命令 http://blog.csdn.net/jackalfly/article/details/7556848 cat主要有三大功能:1.一次显示整个文件.$ cat filena ...
- python库——h5py入门讲解
本文只是简单的对h5py库的基本创建文件,数据集和读取数据的方式进行介绍,作者刚接触h5py,完全靠看文档自学,如果哪里说的不对,欢迎纠正!如果读者需要进一步详细的学习h5py的更多知识,请参考h5p ...
- debian 中的jdk
1 openjdk 2 debian安装java的脚本 3 下载bin自己编译