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 ...
随机推荐
- 排名Top 100的Java类库
和去年一样,排名第一的类库,依旧是JUnit.基于它扩展的 JUnit Runner 占据第二名的位置,甚至是较旧的 junit.framework 此次也在第三名的位置.也就是说JUnit包揽了前三 ...
- 再读headfirst-原则与模式摘录
原则 1.找到原则中可能需要变化之处,把它们独立出来,不要和那些不需要变化的代码混在一起 2.针对接口编程,而不是针对实现编程 3.多用组合,少用继承 4.依赖倒置原则:要依赖抽象,不要依赖具体类(不 ...
- query或者JavaScript实现在textarea光标处插入文本
1.Jquery函数实现: $(function() { /* 在textarea处插入文本--Start */ (function($) { $.fn.extend({ insertContent ...
- js moment.js日期操作类 datetime,日期操作,dayjs
http://momentjs.com/ JS时间处理插件MomentJS https://juejin.im/post/5a2bdc55f265da432b4abf5e Day.js 2kB超轻量时 ...
- [App Store Connect帮助]六、测试 Beta 版本(4.2) 管理 Beta 版构建版本:查看构建版本状态和指标
必要职能:“帐户持有人”职能.“管理”职能.“App 管理”职能.“开发者”职能或“营销”职能.请参见职能权限. 在首页上,点按“我的 App”,选择您的 App,然后在工具栏中点按“TestFlig ...
- JAVA POI的使用
最近开发遇到了要通过Java处理Excel文件的场景,于是乎在网上了解了一番,最后自己做了个demo,已上传gitee:https://gitee.com/github-26930945/JavaCo ...
- python自动化测试学习笔记-unittest参数化
做接口测试的时候,当一个参数需要输入多个值的时候,就可以使用参数来实现: python中unittest单元测试,可以使用nose_parameterized来实现: 首先需要安装:pip inst ...
- ASP.Net 知识点总结(四)
1.get和post 的区别 get是从服务器上获取数据,post是向服务器传送数据; get安全性非常低,数据显示在地址栏,post安全性较高: 但是执行效率却比Post方法好: get有字节限制为 ...
- 2017西安网络赛B_Coin
样例输入 2 2 1 1 3 1 2 样例输出 500000004 555555560 思路: n重伯努利实验概率分布题. 设q=1-p,p为事件概率. Y为出现偶数次的概率. 所以 Y=1/2*( ...
- E - Cheap Kangaroo(求多个数的最大公约数)
Description There are N kangaroos going out to eat at an Indian restaurant. The ith kangaroo wants t ...