TopCoder problem "TwoBoxes" used in SRM 30 (Division I Level One , Division II Level One)



Problem Statement

    
Class name: TwoBoxes
Method name: enclosedVolume
Parameters: int[], int[]
Returns: int

Implement a class TwoBoxes, which contains a method enclosedVolume.
enclosedVolume returns the union of volumes enclosed by two rectangular boxes;
where the union of volumes is defined as the sum of the individual volumes
minus the volume of their intersection.  Boxes' edges are parallel to the
coordinate axes.  Boxes may intersect, but need not intersect.  The position of
each box in coordinate space is specified by its near lower-left corner and far
upper-right corner.

    ______
  /       /| <-- far upper-right corner
 /       / |
/______ /  |
|      |   |
|      |  /
|      | /
|______|/
^
|
near lower-left corner


The method signature is (be sure to declare the method to be public):
int enclosedVolume( int[] Apoints, int[] Bpoints )
*Parameter Apoints:  int[] =  { AX0, AY0, AZ0, AX1, AY1, AZ1 }
*Parameter Bpoints:  int[] =  { BX0, BY0, BZ0, BX1, BY1, BZ1 }
*All elements in both arrays are within the [-100..100] range (TopCoder will
verify that).
*(AX0,AY0,AZ0) specifies the position of the near lower-left corner of the
first box.
*(AX1,AY1,AZ1) specifies the position of the far upper-right corner of the
first box. TopCoder will ensure that AX1 >= AX0, AY1 >= AY0, and AZ1 >= AZ0.
*(BX0,BY0,BZ0) specifies the position of the near lower-left corner of the
second box.
*(BX1,BY1,BZ1) specifies the position of the far upper-right corner of the
second box. TopCoder will ensure that BX1 >= BX0, BY1 >= BY0, and BZ1 >= BZ0.

Examples:
-If the corners of the first box are located at (0,0,0) (10,10,10) and the
corners of the second box are located at (-5,-5,-5) (5,5,5), then the volume of
the first box is 10*10*10=1000, the volume of the second box is 10*10*10=1000,
the volume of the intersection is 5*5*5=125, and the total volume enclosed by
two boxes is 1000+1000-125=1875.

-If the corners of the first box are located at (-10,-10,-10) (10,10,10) and
the corners of the second box are located at (-5,-5,-5) (5,5,5), then the
volume of the first box is 20*20*20=8000, the volume of the second box is
10*10*10=1000, the second box is completely enclosed by the first, so the total
volume enclosed by two boxes is 8000.

-If the corners of the first box are located at (0,0,0) (10,10,10) and the
corners of the second box are located at (-10,-10,-10) (0,0,0), then the volume
of the first box is 10*10*10=1000, the volume of the second box is
10*10*10=1000, the boxes do not intersect, so the total volume enclosed by two
boxes is 1000+1000=2000.
-If the corners of the first box are located at (10,10,10) (10,10,10) and the
corners of the second box are located at (-10,-10,-10) (0,0,0), then the volume
of the first box is 0*0*0=0, the volume of the second box is 10*10*10=1000, the
boxes do not intersect, so the total volume enclosed by two boxes is 0+1000=1000.
 

Definition

    
Class:TwoBoxes
Method:enclosedVolume
Parameters:int[], int[]
Returns:int
Method signature:int enclosedVolume(int[] param0, int[] param1)
(be sure your method is public)
    

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=165

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=4000&pm=165

Writer:

kyky

Testers:

Problem categories: