题目链接:http://www.51nod.com/Challenge/Problem.html#!#problemId=1264

检查点的位置就行了,具体见注释。

 /*  (a-c)×(d-c)*(d-c)×(b-c)>=0检查c点在ab之间
&&(c-a)×(b-a)*(b-a)×(d-a)>= 0检查a点在cd之间
就可以判断ab,cd相交(可以画个图看看)
(x1,y1)×(x2,y2) = x1y2 - x2y1 (向量积)*/
#include <iostream>
#include <cstdio>
using namespace std;
struct point{ double x,y; };; bool cross(point a,point b,point c,point d){//检查c点在ab之间
double p=(a.x-c.x)*(d.y-c.y)-(d.x-c.x)*(a.y-c.y);//CA×CD
double q=(d.x-c.x)*(b.y-c.y)-(b.x-c.x)*(d.y-c.y);//CD×CB
if(p*q<) return false;
else return true;
}
int main(){ int t; scanf("%d",&t);
while(t--){
point a,b,c,d;
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&d.x,&d.y);
if(cross(a,b,c,d)&&cross(c,d,a,b))
puts("Yes");
else
puts("No");
}
}
05-19 13:00