14967 - Advanced Rectangle Algebra System   

Description

In computational geometry, managing the relationship between spatial objects is a fundamental task. In this problem, you are required to implement a Rectangle Algebra System using C++ Classes and Operator Overloading.

Your goal is to treat geometric rectangles as algebraic elements, where the Intersection, Bounding Box, and Scaling operations are represented by standard operators.

1. Geometric Definition

Each rectangle in this system is a Axis-Aligned Bounding Box and is defined by two points (x1 , y1) and (x2 , y2) on its diagonal. You need to implement the constructor to store these information in a useful way.

2. Algebraic Operators

You must overload the following operators to support complex geometric expressions:

 

  • Intersection (A & B):

    Returns a new Rectangle representing the overlapping area.

    • Identity Logic: If A and B do not overlap, or one's area is 0, then it should return a zero-area rectangle.

  • Modified Union, or Bounding Box (A | B):

    Returns a new Rectangle that is the smallest axis-aligned rectangle containing both A and B.

    • Identity Logic: If A is a zero-area rectangle, then it should return B.

  • Scaling (A * multiplier):

    Returns a new Rectangle scaled by the absolute value of the multiplier from its center point. If the multiplier is negative, the width and height of the rectangle should be swapped after scaling.

    • Identity Logic: If A is a zero-area rectangle, it should return a zero-area rectangle.

  • Assignment (A = B):

    Ensures that rectangles can be assigned to one another safely.

3. Area Calculation

The system must be able to calculate the area of the resulting rectangle.

Constraints

  • 1 <= N <= 100.
  • -106 <= x, y <= 106

Testcase Design

  • Testcase 1~4: Intersection, Bounding Box
  • Testcase 5~6: Intersection, Bounding Box, and Scaling with positive multiplier
  • Testcase 7~8: Unlimited

Input

The first line contains an integer N, the number of rectangles.

The next N lines each contain Name x1 y1 x2 y2.

  • Name: A unique string ID.

  • x1 y1 x2 y2: Coordinates of two opposite corner.

The final line is a space-separated algebraic string. Operators include & (Intersection), | (Bounding Box), and * (Scaling). You must evaluated it from left to right.

Output

A single line containing the area of the final resulting rectangle, with '\n'.

Sample Input  Download

Sample Output  Download

Partial Judge Code

14967.cpp

Partial Judge Header

14967.h

Tags




Discuss