Under construction

Still being built. Things may change

Segment Intersection 1

Interview

Time limit0.25sMemory limit512 MB

Summary
Given the integer endpoints of two segments, decide whether the segments intersect, using orientation tests with no three input points collinear.
Level

Medium5 of 10

Topics
Geometry, Math, Implementation, Brute force
Solved
No attempts yet

Problem

Given two line segments L1L_1 and L2L_2 on the two-dimensional coordinate plane, determine whether the two segments intersect.

The endpoints of L1L_1 are (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2), and the endpoints of L2L_2 are (x3,y3)(x_3, y_3) and (x4,y4)(x_4, y_4).

Input

The first line gives the endpoints x1,y1,x2,y2x_1, y_1, x_2, y_2 of L1L_1, and the second line gives the endpoints x3,y3,x4,y4x_3, y_3, x_4, y_4 of L2L_2. No three points lie on the same line.

Output

Print 1 if L1L_1 and L2L_2 intersect, and 0 otherwise.

Constraints

  • −1 000 000≤x1,y1,x2,y2,x3,y3,x4,y4≤1 000 000-1\,000\,000 \le x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \le 1\,000\,000
  • x1,y1,x2,y2,x3,y3,x4,y4x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 are integers.
  • The length of each segment is greater than 0.

Examples2

  1. Example 1

    Input
    1 1 5 5
    1 5 5 1
    
    Expected output
    1
    
  2. Example 2

    Input
    1 1 5 5
    6 10 10 6
    
    Expected output
    0