D. Pair Of Lines

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct.

You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?

Input

The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given.

Then n lines follow, each line containing two integers x**i and y**i (|x**i|, |y**i| ≤ 109)— coordinates of i-th point. All n points are distinct.

Output

If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.

Examples

input

Copy

50 00 11 11 -12 2

output

Copy

YES

input

Copy

50 01 02 11 12 3

output

Copy

NO

Note

In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.

题意:

给你n个坐标点

问你能不能画两条直线,使所有的点都落在直线上。

(两条直线可以重合)。

思路:

n<=4 直接输出YES

n>=5 时,我们这样考虑:

如果这n个点是满足条件的。

那么两条线上点数中较大的那一个(称为L1)一定大于等于n/2

所以我们可以随机从n个点中选择2个点。

这两点同时落在L1上的概率为\(1/4\)

所以如果这n个点满足条件,我们只需要随机大概4次就可以找到那两条线。

4次只是期望值,N的数据范围是\(1e5\) 所以我们可以随机50次以上,这样更稳。

关于随机到2个点,

我们扫一遍数组,把所有不在这2个确定的直线上的都扔在一个vector里存着。

然后我们再判断vector中所有点是否在同一个直线上。如果有满足条件的就结束随机,输出Yes。

代码:

#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
// #define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {a %= MOD; if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}} inline void getInt(int *p);
const int maxn = 100010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
const double eps = 1e-6;
int sgn(double x)
{
if (fabs(x) < eps) { return 0; }
if (x < 0) { return -1; }
else { return 1; }
}
struct Point {
ll x, y;
Point() {}
Point(double _x, double _y)
{
x = _x; y = _y;
}
void input()
{
cin >> x >> y;
}
Point operator -(const Point &b)const
{
return Point(x - b.x, y - b.y);
} // 111 / 179
//叉积
double operator ^(const Point &b)const
{
return x * b.y - y * b.x;
}
//点积
double operator *(const Point &b)const
{
return x * b.x + y * b.y;
}
//绕原点旋转角度 B(弧度值),后 x,y 的变化
void transXY(double B)
{
double tx = x, ty = y;
x = tx * cos(B) - ty * sin(B);
y = tx * sin(B) + ty * cos(B);
}
};
int n;
Point a[maxn];
std::vector<int> p;
int main()
{
//freopen("D:\\code\\text\\input.txt","r",stdin);
//freopen("D:\\code\\text\\output.txt","w",stdout);
gbtb;
cin >> n;
repd(i, 1, n) {
a[i].input();
}
if (n <= 4) {
cout << "YES" << endl;
return 0;
}
int id1, id2;
mt19937 rnd(time(0));
int isok = 0;
repd(rp, 1, 100) {
p.clear();
id1 = rnd() % n + 1;
do {
id2 = rnd() % n + 1;
} while (id2 == id1);
repd(i, 1, n) {
if (i == id1 || id2 == i) {
continue;
}
if (((a[id2] - a[id1]) ^ (a[i] - a[id1])) != 0) {
p.push_back(i);
}
}
int flag = 1;
for (int i = 2; i < sz(p); ++i) {
if (((a[p[1]] - a[p[0]]) ^ (a[p[i]] - a[p[0]])) != 0) {
flag = 0;
break;
}
}
if (flag) {
isok = 1;
// chu(id1);
// chu(id2);
break;
}
}
if (isok) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
} inline void getInt(int *p)
{
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 - ch + '0';
}
} else {
*p = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 + ch - '0';
}
}
}

Educational Codeforces Round 41 (Rated for Div. 2) D. Pair Of Lines (几何,随机)的更多相关文章

  1. Educational Codeforces Round 41 (Rated for Div. 2)F. k-substrings

    题意比较麻烦略 题解:枚举前缀的中点,二分最远能扩展的地方,lcp来check,然后线段树维护每个点最远被覆盖的地方,然后查询线段树即可 //#pragma GCC optimize(2) //#pr ...

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

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

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

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

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

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

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

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

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

    //暴力 #include <iostream> #include <algorithm> #include <string> using namespace st ...

  7. B. Lecture Sleep( Educational Codeforces Round 41 (Rated for Div. 2))

    前缀后缀和搞一搞,然后枚举一下区间,找出最大值 #include <iostream> #include <algorithm> using namespace std; ; ...

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

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

  9. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

随机推荐

  1. CentOS的开发环境配置(Python、Java、php)

    CentOS安装Python 一.Python源代码编译安装 yum -y install wget yum -y install zlib zlib-devel yum -y install bzi ...

  2. macos的iptables功能是pfctl

    pfctl https://www.kokaruk.com/macos-pf-firewall/ https://blog.csdn.net/yjy1304/article/details/90762 ...

  3. centos/Fedora/RHEL 安全设置

    centos/Fedora/RHEL •     整改方法: •     验证检查:  1.查看/etc/login.defs,访谈询问当前所设置的密码长度及更换周期:  2.查看/etc/pam.d ...

  4. 封装transform函数(设置和获取transform的属性和属性值)

    (function (w) { /** * 设置或者获取元素的transform属性值 * @param node 要设置的元素 * @param param 变换属性: translate\scal ...

  5. dotnet core JWT Demo

    JWT介绍 JSON Web Token(JWT)是目前最流行的跨域身份验证解决方案.JWT的官网地址:https://jwt.io/. 通俗地来讲,JWT是能代表用户身份的令牌,可以使用JWT令牌在 ...

  6. LocalDate LocalTime LocalDateTime Instant的操作与使用

    一.简介 LocalDate表示当前(或指定)日期,格式为:yyyy-MM-dd LocalTime表示当前(或指定)时间,格式为:HH:mm:ss SSS LocalDateTime表示当前(或指定 ...

  7. fork() 函数简介

    fork() 函数简介 fork系统调用用于创建一个新进程,称为子进程,它与进行fork()调用的进程(父进程)并发运行.创建新的子进程后,两个进程都将执行fork()系统调用之后的下一条指令.子进程 ...

  8. xsy 2414【CF587C】Duff in the Army

    Description [题目描述]: 最近有一场战争发生,Duff是战争里一名士兵,Malek是她的长官. 他们的国家——Andarz Gu有n个城市(编号为1到n),总共有n-1条道路,每条道路连 ...

  9. centos 6.10 oracle 19c安装

    centos 7以下版本安装oracle 19c 问题较多,centos 以上版本没有任何问题.记录如下. hosts文件,否则图形界面无法启动 127.0.0.1 localhost localho ...

  10. Python random模块(以后用到一个再更新一个)

    random模块是产生随机数的模块 1.random.random() 这是产生0~1之间一个随机浮点数,但是不会包括1 import random num = 0 while num < 10 ...