【题意概述】

  给出平面上的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)的更多相关文章

  1. Educational Codeforces Round 41

    Educational Codeforces Round 41  D. Pair Of Lines 考虑先把凸包找出来,如果凸包上的点数大于\(4\)显然不存在解,小于等于\(2\)必然存在解 否则枚 ...

  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 ...

  3. 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 ...

  4. Educational Codeforces Round 41 (Rated for Div. 2)(A~D)

    由于之前打过了这场比赛的E题,而后面两道题太难,所以就手速半个多小时A了前4题. 就当练手速吧,不过今天除了C题数组开小了以外都是1A A Tetris 题意的抽象解释可以在Luogu里看一下(话说现 ...

  5. Educational Codeforces Round 41 (Rated for Div. 2)

    这场没打又亏疯了!!! A - Tetris : 类似俄罗斯方块,模拟一下就好啦. #include<bits/stdc++.h> #define fi first #define se ...

  6. Educational Codeforces Round 41 (Rated for Div. 2) ABCDEF

    最近打的比较少...就只有这么点题解了. A. Tetris time limit per test 1 second memory limit per test 256 megabytes inpu ...

  7. Educational Codeforces Round 41 A B C D E

    A. Tetris 题意 俄罗斯方块,问能得多少分. 思路 即求最小值 Code #include <bits/stdc++.h> #define F(i, a, b) for (int ...

  8. 【Educational Codeforces Round 41 (Rated for Div. 2) D】Pair Of Lines

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果点的个数<=3 那么直接输出有解. 否则. 假设1,2最后会在一条直线上,则把这条直线上的点都删掉. 看看剩余的点是否在同 ...

  9. D. Pair Of Lines( Educational Codeforces Round 41 (Rated for Div. 2))

    #include <vector> #include <iostream> #include <algorithm> using namespace std; ty ...

随机推荐

  1. NOI.AC #31 MST —— Kruskal+点集DP

    题目:http://noi.ac/problem/31 好题啊! 题意很明白,对于有关最小生成树(MST)的题,一般是要模拟 Kruskal 过程了: 模拟 Kruskal,也就是把给出的 n-1 条 ...

  2. mysql通用分页存储过程遇到的问题(转载)

    mysql通用分页存储过程遇到的问题(转载) http://www.cnblogs.com/daoxuebao/archive/2015/02/09/4281980.html

  3. C头文件中尖括号与双引号的区别及编译搜索顺序

    这两天被问到一个很有意思的问题:C头文件中尖括号与双引号有什么区别,以前只大约知道 <> 常用在系统库文件,"" 常用在自定义的借口文件中,那具体在gcc编译搜索过程中 ...

  4. php 文件上传限制修改

    修改PHP上传文件大小限制的方法 1. 一般的文件上传,除非文件很小.就像一个5M的文件,很可能要超过一分钟才能上传完.但在php中,默认的该页最久执行时间为 30 秒.就是说超过30秒,该脚本就停止 ...

  5. hdu6198 number number number(递推公式黑科技)

    number number number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  6. 洛谷 P3389 【模板】高斯消元法

    以下这个好像叫高斯约旦消元法,没有回代 https://www.luogu.org/blog/37781/solution-p3389 #include<cstdio> #include& ...

  7. BFS(两点搜索) FZOJ 2150 Fire Game

    题目传送门 题意:'#'表示草地,两个人在草地上点火,相邻的草地会烧起来,每烧一格等1秒,问最少要等几秒草地才烧完 分析:这题和UVA 11624 Fire!有点像,那题给定了两个点,这题两点不确定, ...

  8. 题解报告:poj 2386 Lake Counting(dfs求最大连通块的个数)

    Description Due to recent rains, water has pooled in various places in Farmer John's field, which is ...

  9. EditText(3)输入时自动完成功能

    在android输入自动完成功能由EditText的子类 AutoCompleteTextView 实现.如下: 1,在xml中使用 <AutoCompleteTextView android: ...

  10. connection failed to http://nssa-sensor3:11000/oozie/?user.name=oozie(<urlopen erroer Errno 111] Connection refused>)解决办法(图文详解)

    不多说,直接上干货! 解决办法 Copy/Paste oozie.services property tag set from oozie-default.xml to oozie-site.xml. ...