Yes
No
代码:
#include
#include
int T;
double x1, y, x2, y2, x3, y3, x4, y4;
void fun()
{
double k1, k2, b1, b2;
k1 = (y2 - y) / (x2 - x1);
k2 = (y4 - y3) / (x4 - x3);
b1 = y - k1*x1;
b2 = y3 - k2*x3;
double t;
if (x1>x2) { t = x1; x1 = x2; x2 = t; }
if (x3>x4) { t = x3; x3 = x4; x4 = t; }
if (y>y2) { t = y; y = y2; y2 = t; }
if (y3>y4) { t = y3; y3 = y4; y4 = t; }
if (k1 == k2 && b1 != b2) { printf("No\n"); return; }
else if (k1 == k2 && b1==b2)
{
if (x4x2) { printf("No\n"); return; }
else { printf("Yes\n"); return; }
}
else if (k1 != k2)
{
double x = (b2 - b1) / (k1 - k2);
if (x <= x2&&x >= x1&&x <= x4&&x >= x3) { printf("Yes\n"); return; }
else { printf("No\n"); return; }
}
}
int main()
{
scanf("%d", &T);
while (T--)
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1, &y, &x2, &y2, &x3, &y3, &x4, &y4);
fun();
}
return 0;
}
有问题欢迎私聊和评论~么么哒~(难的不会写 哈哈 只有简单的)