#include <iostream>
using namespace std;

typedef struct{
    float x;
    float y;
}TPonto;

/********************************************************************
  direcao(pi,pj,pk) determina para que lado estaria o novo segmento
*********************************************************************/
/*
 segmento pkpj à esquerda | segmento pjpk à direita
    pk       pj           |      pj        pk
    ._______ .            |     .__________.
            /             |      \
           /              |       \
          /               |        \
         .                |         .
        pi                |          pi

*/
double direcao(TPonto pi, TPonto pj, TPonto pk){
   TPonto Vik,Vij;

   Vik = {pk.x-pi.x,pk.y-pi.y};
   Vij = {pj.x-pi.x,pj.y-pi.y};

   if ((Vik.x*Vij.y - Vik.y*Vij.x)<0) // <0 esquerda
      return 0;
   return 1;
}

bool onSegment(TPonto pi,TPonto pj,TPonto pk){
   //se (min(xi,xj)<=xk<=max(xi,xj)) e (min(yi,yj)<=yk<=max(yi,yj))
   if( ((min(pi.x,pj.x) <= pk.x) && (pk.x <= max(pi.x,pj.x))) && ((min(pi.y,pj.y) <= pk.y) && (pk.y <= max(pi.y,pj.y))) )
	   return true;
   return false;
}	

/*                                     ____   ____
  Verifica a intersecção dos segmentos p1p2 e p3p4
*/
bool Intersect(TPonto p1, TPonto p2, TPonto p3, TPonto p4){
   double d1,d2,d3,d4;
   d1=direcao(p3, p4, p1);//p2,q2,p1
   d2=direcao(p3, p4, p2);//p2,q2,q1
   d3=direcao(p1, p2, p3);//p1,q1,p2
   d4=direcao(p1, p2, p4);//p1,q1,q2
   if ((d1!=d2) && (d3!=d4)) 
        return true;
   else if(d1==0 && onSegment(p3,p4,p1))
        return true;
   else if(d2==0 && onSegment(p3,p4,p2)) 
        return true;
   else if(d3==0 && onSegment(p1,p2,p3))
        return true;
   else if(d4==0 && onSegment(p1,p2,p4))
        return true;

   return false;
}	

//
//Verificar outro modo em https://acervolima.com/como-verificar-se-dois-segmentos-de-linha-dados-se-cruzam/
//
   
int main(void){
    TPonto p1,q1,p2,q2;
    /*  
    TPonto p1,p2,p3,p4;    
    p1={5,5}; p2={2,7};
    p3={3,4}; p4={6,6}; */
    
    p1 = {1, 1}, q1 = {10, 1};
    p2 = {1, 2}, q2 = {10, 2};
    Intersect(p1, q1, p2, q2)? cout << "Yes\n": cout << "No\n";
    /*if (Intersect(p1, p2, p3, p4)) 
       cout<<"\nAs arestas se cruzam\n";
    else cout<<"\nAs arestas não se cruzam\n";*/

    p1 = {10, 0}, q1 = {0, 10};
    p2 = {0, 0}, q2 = {10, 10};
    Intersect(p1, q1, p2, q2)? cout << "Yes\n": cout << "No\n";
    /*if (Intersect(p1, p4, p2, p3)) 
       cout<<"\nAs arestas se cruzam\n";
    else cout<<"\nAs arestas não se cruzam\n";*/
    
    p1 = {-5, -5}, q1 = {0, 0};
    p2 = {1, 1}, q2 = {10, 10};
    Intersect(p1, q1, p2, q2)? cout << "Yes\n": cout << "No\n";
    
    return 0;
}
