#C9157. Overlapping Rectangles

    ID: 53219 Type: Default 1000ms 256MiB

Overlapping Rectangles

Overlapping Rectangles

Given the coordinates of the bottom-left and top-right corners of two axis-aligned rectangles, determine whether they overlap. Two rectangles are considered to overlap if they share any area. Note that if the rectangles only touch along their borders (with no actual intersecting area), they are considered not to overlap.

The coordinates are provided as eight integers:

  • X1, Y1: bottom-left corner of the first rectangle
  • X2, Y2: top-right corner of the first rectangle
  • X3, Y3: bottom-left corner of the second rectangle
  • X4, Y4: top-right corner of the second rectangle

Your task is to determine if the rectangles overlap. Output 1 if they do, and 0 otherwise.

The condition for overlap can be mathematically formulated as:

\( \text{if } (X1 \ge X4) \text{ or } (X3 \ge X2) \text{ or } (Y1 \ge Y4) \text{ or } (Y3 \ge Y2) \text{ then no overlap; otherwise, they overlap.} \)

inputFormat

The input consists of a single line containing eight space-separated integers: X1 Y1 X2 Y2 X3 Y3 X4 Y4, representing the coordinates of the two rectangles as described above.

outputFormat

Output a single integer: 1 if the rectangles overlap (i.e., share some area), and 0 if they do not.## sample

1 1 4 4 2 2 5 5
1