// 取前三个点 若存在这样两条线 其中两点间连线必为两条之一
// 不在这条直线上的点是否在同一直线上
#include <bits/stdc++.h>
using namespace std;
const int mn = 100010;
long long x[mn], y[mn];
int main()
{
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%lld %lld", &x[i], &y[i]);
if (n <= 4)
{
printf("YES\n");
return 0;
}
bool flag = 0;
for (int i = 1; i <= 2; i++)
{
for (int j = i + 1; j <= 3; j++)
{
long long a = y[j] - y[i];
long long b = x[i] - x[j];
long long c = y[i] * x[j] - y[j] * x[i];
long long xa , ya, xb, yb;
int t = 0;
int k = 1;
for (k = 1; k <= n; k++)
{
if (a * x[k] + b * y[k] + c == 0)
continue;
else
{
t ++; // 不在这条直线上点的数量
if (t == 1)
xa = x[k], ya = y[k];
else if(t == 2)
xb = x[k], yb = y[k];
else
break;
}
}
if (t <= 2)
{
flag = 1;
break;
}
long long ta = yb - ya;
long long tb = xa - xb;
long long tc = ya * xb - yb * xa;
bool q = 0; // 是否有不在两条直线上的
for (int p = k; p <= n; p++)
{
if ((a * x[p] + b * y[p] + c == 0) || ta * x[p] + tb * y[p] + tc == 0)
continue;
else
q = 1;
if (q)
break;
}
if (!q)
{
flag = 1;
break;
}
}
if (flag)
break;
}
if (!flag)
printf("NO\n");
else
printf("YES\n");
return 0;
}
【几何】 Pair Of Lines CF contest961 D
最新推荐文章于 2020-02-29 23:24:25 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)