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 ...
随机推荐
- gitlab调试
Bundle complete! 104 Gemfile dependencies, 161 gems now installed.Gems in the groups development, te ...
- 2-3 原生小程序 - 项目app.json配置
App.json它其实有四五个配置,但是最重要的是pages.windows和tabbar.tabbar是做导航的处理的. 官方推荐的入门配置之一: app.json 它其实有一些字段是限制了这个格式 ...
- System.Drawing.Color的几种使用方法
System.Drawing.Color cl = Color.Red; System.Drawing.Color cl = Color.FromArgb(255,0,0); ...
- UVaLive 6834 Shopping (贪心)
题意:给定 n 个商店,然后有 m个限制,去 c 之前必须先去d,问你从0到n+1,最短路程是多少. 析:我们我们要到c,必须要先到d,那么举个例子,2 5, 3 7,如果我们先到5再到2,再到7再到 ...
- 一个简陋的个人小项目,也是个人第一个真正意义上的独立项目——Graph
由来 我最早接触到图这个概念是在大二的离散数学当中图论相关的内容,当时是以著名的哥尼斯堡七桥问题引出图论的概念,现在依然记忆犹新(不过只是记得这个名字,具体的解题思路我重新温习了一下才想起来),当时也 ...
- golang——strconv包常用函数
1.func ParseBool(str string) (value bool, err error) 返回字符串表示的bool值.它接受1.0.t.f.T.F.true.false.True.Fa ...
- T-SQL编程以及常用函数
1.索引添加索引,设计界面,在任何一列前右键--索引/键--点击进入添加某一列为索引 2.视图 视图就是我们查询出来的虚拟表创建视图:create view 视图名 as SQL查询语句,分组,排序, ...
- Python,报错NameError: name 'math' is not defined
1 #-*- coding : utf-8 -*- 2 import math 3 4 def move(x, y, step, angle=0): 5 nx = x + step * math.co ...
- [算法天天练] - C语言实现双向链表(一)
双向链表是比较常见的,主要是在链表的基础上添加prev指针,闲话少说直接上代码吧(这个也是网上一个大神的思路,真心不错,条理清楚,逻辑缜密) 主要也是为了学习,贴上我所调试成功的代码(Linux环境下 ...
- 简述 MVC, MVP, MVVM三种模式
Make everything as simple as possible, but not simpler - Albert Einstein* 把每件事,做简单到极致,但又不过于简单 - 阿尔伯特 ...