holiday/8.10/C-edge/C-edge.cpp
2022-08-12 15:37:34 +08:00

109 lines
1.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
const double inf = 1e100, EPS = 1e-8;
const int N = 101;
double l, now;
int n,t;
struct edge
{
double x[2], y[2];
} e[N];
// WA double 判断正负要用
int sign(double d)
{
if (fabs(d) < EPS)
{
return 0;
}
else
return d > 0 ? 1 : -1;
}
double cross(double x1, double y1, double x2, double y2)
{
return x1 * y2 - x2 * y1;
}
int same(double x0, double y0, double x3, double y3, double x1, double y1, double x2, double y2)
{
double x = x3 - x0, y = y3 - y0; // y0->x0
//WA 没有用浮点数的大小比较方法
return sign(cross(x, y, x1 - x0, y1 - y0)) * sign(cross(x, y, x2 - x0, y2 - y0));
}
//与所有边比是否相交
bool ob(int x0, int y0, int x1, int y1)
{
for (int i = 1; i <= n; i++)
{
if (sign(same(x0,y0,x1,y1,e[i].x[0],e[i].y[0],e[i].x[1],e[i].y[1])) > 0)
{
return 0;
}
}
return 1;
}
//另一线段的点,连点成线
bool dot2(int ii, int jj)
{
for (int i = 1; i <= n; i++)
{
if (i == ii)
continue;
for (int j = 0; j < 2; j++)
{
if(sign(e[ii].x[jj]-e[i].x[j])==0&&sign(e[ii].y[jj]-e[i].y[j])==0) continue;
if (ob(e[ii].x[jj], e[ii].y[jj], e[i].x[j], e[i].y[j]))
{
return 1;
}
}
}
return 0;
}
//找一个点
bool adot()
{
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < 2; j++)
{
if (dot2(i, j))
{
return 1;
}
}
}
return 0;
}
int main()
{
scanf("%d", &t);
while (t--)
{
scanf("%d", &n);
memset(&e, 0, sizeof(edge) * (n + 1));
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < 2; j++) // 又是j
{
scanf("%lf%lf", &e[i].x[j], &e[i].y[j]);//少一个%lf
}
}
if(n==1)
{
printf("Yes!\n");
continue;
}
if(adot())
{
printf("Yes!\n");
}
else
{
printf("No!\n");
}
}
return 0;
}