51Nod 1264 线段相交
/* (a-c)×(d-c)*(d-c)×(b-c)>=0&&(c-a)×(b-a)*(b-a)×(d-a)>= 0就可以判断ab,cd相交*/ /* p1×p2 = x1y2 - x2y1 = - p2×p1-----(叉乘公式)叉积*/ #include<stdio.h> struct point { double x,y; }; //struct point a,b,c,d; int mp(point a,point b,point c,point d){ double C=(a.x-c.x)*(d.y-c.y)-(d.x-c.x)*(a.y-c.y); double D=(d.x-c.x)*(b.y-c.y)-(b.x-c.x)*(d.y-c.y); if(C*D<0) return 0; else return 1; } bool check(point a , point b , point c , point d){ if(!mp(a,b,c,d)) return false; if(!mp(c,d,a,b)) return false; 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(check(a,b,c,d)) printf("Yes\n"); else printf("No\n"); } }