struct point{
    double x,y ;
} ;
double direction(point p1,point p2,point p)
{
    return (p.x-p1.x)*(p1.y-p2.y)-(p1.x-p2.x)*(p.y-p1.y) ;
}
bool online(point p1,point p2,point p)
{
    return (p.x<=max(p1.x,p2.x) && p.x>=min(p1.x,p2.x) && p.y<=max(p1.y,p2.y) && p.y>=min(p1.y,p2.y)) ;
}
bool intersect(point p1,point p2,point p3,point p4)
{
    double d1=direction(p3,p4,p1) ;
    double d2=direction(p3,p4,p2) ;
    double d3=direction(p1,p2,p3) ;
    double d4=direction(p1,p2,p4) ;
    if(d1*d2<0 && d3*d4<0)
        return true ;
    if(d1==0 && online(p3,p4,p1)) 
        return true ;
    if(d2==0 && online(p3,p4,p2))
        return true ;
    if(d3==0 && online(p1,p2,p3))
        return true ;
    if(d4==0 && online(p1,p2,p4))
        return true ;
    return false ;
}
View Code