#K91537. Rectangle Intersection Area
Rectangle Intersection Area
Rectangle Intersection Area
In this problem, you are given the coordinates of two rectangles and are required to determine whether they overlap. If they do, compute the area of their overlapping region.
Each rectangle is represented by two points: the bottom-left and the top-right coordinates. Let the first rectangle be given by \( (x_1, y_1) \) and \( (x_2, y_2) \), and the second rectangle by \( (x_3, y_3) \) and \( (x_4, y_4) \). The boundaries for the overlapping region can be computed as follows:
\[ x_{left} = \max(x_1, x_3), \quad y_{bottom} = \max(y_1, y_3) \]
\[ x_{right} = \min(x_2, x_4), \quad y_{top} = \min(y_2, y_4) \]
An overlapping area exists if and only if \( x_{left} < x_{right} \) and \( y_{bottom} < y_{top} \). If the rectangles overlap, output yes
followed by the area of the overlapping region; otherwise, output no 0
.
The input consists of multiple datasets. Each dataset contains two lines, with each line having 4 integers (separated by spaces) representing the coordinates of a rectangle. The input terminates when a line containing a single zero is encountered.
inputFormat
Input is provided via standard input. The input consists of multiple datasets. Each dataset is composed of two lines:
- The first line contains four integers:
x1 y1 x2 y2
representing the first rectangle. - The second line contains four integers:
x3 y3 x4 y4
representing the second rectangle.
Datasets are processed in pairs until a line with a single 0
is encountered, which signals the end of input.
outputFormat
For each dataset, output a single line to standard output. If the rectangles overlap, output yes
followed by the area of intersection. Otherwise, output no 0
. Each result should be on its own line.
1 1 4 4
2 2 5 5
0
yes 4