【题意概述】

  给出平面上的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. Python基础Web服务器案例

    一.WSGI 1.PythonWeb服务器网关接口(Python Web Server Gateway Interface,缩写为WSGI) 是Python应用程序或框架和Web服务器之间的一种接口, ...

  2. C#实现的鼠标钩子

    http://www.oschina.net/code/snippet_104607_45975 使用 Socket 获得网页内容,可以捕获错误页的内容 HttpClient http://www.o ...

  3. bzoj 1630: [Usaco2007 Demo]Ant Counting【dp】

    满脑子组合数学,根本没想到dp 设f[i][j]为前i只蚂蚁,选出j只的方案数,初始状态为f[0][0]=1 转移为 \[ f[i][j]=\sum_{k=0}^{a[i]}f[i-1][j-k] \ ...

  4. bzoj3450 Easy(概率期望dp)

    3450: Tyvj1952 Easy Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 876  Solved: 648[Submit][Status] ...

  5. bzoj1015星球大战(并查集+离线)

    1015: [JSOI2008]星球大战starwar Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 5572  Solved: 2563 Descri ...

  6. 数学 FZU 2074 Number of methods

    题目传送门 /* 数学:假设取了第i个,有C(n-1)(i-1)种取法 则ans = sum (C(n-1)(i-1)) (1<i<=n) 即2^(n-1) */ #include < ...

  7. canvas学写一个字

    第一步:画一个米字格,先画一个矩形,再画中间的米字. <script> window.onload = function(){ var canvas = document.getEleme ...

  8. 299 Bulls and Cows 猜数字游戏

    你正在和你的朋友玩猜数字(Bulls and Cows)游戏:你写下一个数字让你的朋友猜.每次他猜测后,你给他一个提示,告诉他有多少位数字和确切位置都猜对了(称为”Bulls“, 公牛),有多少位数字 ...

  9. The Chosen One

    https://www.hackerrank.com/contests/101hack45/challenges/the-chosen-one 找出一个数字,使得,数组中只有一个数字不是这个数的约数, ...

  10. C# 代码笔记_文件

           string Route = @"D:\ksy\ksy\WebSite1\";//文件地址         string File_name = "user ...