Educational Codeforces Round 41 D. Pair Of Lines(961D)

【题意概述】
给出平面上的10W个点,要求判断这些点能否被两条直线穿过,即一个点至少在一条直线上。
【题解】
思路很快可以想到。取3个不共线的点,它们形成一个三角形;如果有解,其中的一条直线一定与三角形的一条边重合。于是用这三条边一一进行验证即可。
第一次交被卡了精度,后来意识到判断三个点是否共线写丑了,其实并不需要求解析式。直接运用相似三角形,移项变成乘法即可。
#include<cstdio>
#include<algorithm>
#include<cstring>
#define LL long long
#define rg register
#define N 200010
using namespace std;
int n;
bool v[N];
struct rec{
int x,y;
}p[N];
inline int read(){
int k=,f=; char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(''<=c&&c<='')k=k*+c-'',c=getchar();
return k*f;
}
inline bool cmp(rec a,rec b){
return a.x==b.x?a.y<b.y:a.x<b.x;
}
inline bool ok(rec a,rec b){
return a.x==b.x&&a.y==b.y;
}
inline void cal(rec a,rec b,rec &t){
if(a.x<b.x) swap(a,b);
t.x=a.x-b.x; t.y=a.y-b.y;
}
inline bool judge(rec p1,rec p2,rec p3){
rec t1,t2;
cal(p1,p2,t1); cal(p1,p3,t2);
return 1ll*t1.x*t2.y-1ll*t1.y*t2.x;
}
inline bool check(rec p1,rec p2){
memset(v,,sizeof(v));
for(rg int i=;i<=n;i++) if(!judge(p1,p2,p[i])) v[i]=;
rec p3,p4; int cnt=;
for(rg int i=;i<=n;i++) if(!v[i]){
if(!cnt) p3=p[i],cnt++;
else p4=p[i],cnt++;
}
if(cnt<=) return ;
for(rg int i=;i<=n;i++) if((!v[i])&&(!judge(p3,p4,p[i]))) v[i]=;
for(rg int i=;i<=n;i++) if(!v[i]) return ;
return ;
}
int main(){
n=read();
if(n<=){
puts("YES"); return ;
}
for(rg int i=;i<=n;i++) p[i].x=read(),p[i].y=read();
sort(p+,p++n,cmp);
n=unique(p+,p++n,ok)-p-;
rec p1=p[],p2=p[],p3;
// for(rg int i=1;i<=n;i++) printf("[%d %d]\n",p[i].x,p[i].y); puts("");
for(rg int i=;i<=n;i++) if(judge(p1,p2,p[i])){
p3=p[i];
break;
}
if(check(p1,p2)||check(p1,p3)||check(p2,p3)){
puts("YES");
return ;
}
puts("NO");
return ;
}
Educational Codeforces Round 41 D. Pair Of Lines(961D)的更多相关文章
- Educational Codeforces Round 41
Educational Codeforces Round 41 D. Pair Of Lines 考虑先把凸包找出来,如果凸包上的点数大于\(4\)显然不存在解,小于等于\(2\)必然存在解 否则枚 ...
- Educational Codeforces Round 41 967 E. Tufurama (CDQ分治 求 二维点数)
Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama (CDQ分治 求 二维点数) time limit per test 2 ...
- 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)(A~D)
由于之前打过了这场比赛的E题,而后面两道题太难,所以就手速半个多小时A了前4题. 就当练手速吧,不过今天除了C题数组开小了以外都是1A A Tetris 题意的抽象解释可以在Luogu里看一下(话说现 ...
- Educational Codeforces Round 41 (Rated for Div. 2)
这场没打又亏疯了!!! A - Tetris : 类似俄罗斯方块,模拟一下就好啦. #include<bits/stdc++.h> #define fi first #define se ...
- Educational Codeforces Round 41 (Rated for Div. 2) ABCDEF
最近打的比较少...就只有这么点题解了. A. Tetris time limit per test 1 second memory limit per test 256 megabytes inpu ...
- Educational Codeforces Round 41 A B C D E
A. Tetris 题意 俄罗斯方块,问能得多少分. 思路 即求最小值 Code #include <bits/stdc++.h> #define F(i, a, b) for (int ...
- 【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 ...
随机推荐
- 手推FP-growth (频繁模式增长)算法------挖掘频繁项集
一.频繁项集挖掘为什么会出现FP-growth呢? 原因:这得从Apriori算法的原理说起,Apriori会产生大量候选项集(就是连接后产生的),在剪枝时,需要扫描整个数据库(就是给出的数据),通过 ...
- sql时间截取与修改
--修改日,从1号修改到10号UPDATE CHECKINOUT SET CHECKTIME=DATEADD(DAY,9,CHECKTIME) WHERE YEAR(CHECKTIME)=1970 a ...
- KeepAlived的配置
KeepAlived的相关配置 KeepAlived 配置 参考帮助 man keepalived.conf 配置文件组件部分: top hierachy(层次) global configurati ...
- SQL Server 添加描述
添加描述的格式 exec sys.sp_addextendedproperty @name = N'MS_Description' ,@value = 'value',@level0type=N'SC ...
- 栗染-github中搭建博客遇到的问题之一
运行命令:git push -u origin master To https://github.com/xuzhezhaozhao/Practice.git ! [rejected] master ...
- 清北考前刷题day6早安
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #d ...
- robotframework - create dictionary 操作
1.创建字典 2.从字典中获取的项 -- 打印出 item 3.获取字典的key -- 打印出 key 4.获取字典的value -- 打印出 value 5.获取字典key,value 6.打印出字 ...
- Akka源码分析-Cluster-DistributedData
上一篇博客我们研究了集群的分片源码,虽然akka的集群分片的初衷是用来解决actor分布的,但如果我们稍加改造就可以很轻松的开发出一个简单的分布式缓存系统,怎么做?哈哈很简单啊,实体actor的id就 ...
- C - GCD LCM
Description The GCD of two positive integers is the largest integer that divides both the integers w ...
- Linux 介绍快速浏览
Linux 介绍 内核 库: .so 共享对象,windows:dll 动态链接库 应用程序 Linux的基本原则:1.由目的单一的小程序组成:组合小程序完成复杂任务:2.一切皆文件:3.尽量避免捕获 ...