Intersection of cubes
Time Limit: 500 ms memory limit: 32768kb 64bit Io format: % LLD & % LlU
Submit
Status
Practice
Lightoj 1211
Description
You are given n cubes, each cube is described by two points in 3D space: (x1, Y1, Z1) being one corner of the cube and (X2, Y2, Z2) being the opposite corner. assume that the sides of each of the cubes are parallel to the axis. your task is to find the volume of their intersection.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a line containing an integer N (1 ≤ n ≤ 100 ). each of the next n lines contains six integers X1 Y1 Z1 X2 Y2 Z2 (1 ≤ X1, Y1, Z1, X2, Y2, Z2 ≤ 1000, X1 <X2, Y1 <Y2, z1 <Z2) Where (x1, Y1, Z1) is the co-ordinate of one corner and (X2, Y2, Z2) is the co-ordinate of the opposite corner.
Output
For each case, print the case number and volume of their intersection.
Sample Input
2
2
1 1 1 3 3 3
1 1 1 2 2 2
3
7 8 9 20 20 30
2 2 2 50 50
13 14 15 18 30 40
Sample output
Case 1: 1
Case 2: 450
<Span style = "color: #000099; "> /************************************* * ******* Author: grant yuan time: 2014.8.7 algorithm: Calculate the geometric Source: Light OJ 1211 explain: find the volume of the overlapping cubes ********************************* * *************/# include <iostream> # include <cstdio> # include <cstdlib> # include <cstring> # include <algorithm> # define INF 0x3fffffffusing namespace STD; int t, n, a [7]; int ans; int main () {scanf ("% d", & T); int C; For (INT I = 1; I <= T; I ++) {scanf ("% d", & N); A [1] = A [2] = A [3] = 0; A [4] = A [5] = A [6] = inf; For (Int J = 1; j <= N; j ++) {for (int K = 1; k <= 3; k ++) {scanf ("% d", & C); If (C> A [k]) A [k] = C ;}for (int K = 4; k <= 6; k ++) {scanf ("% d", & C ); if (C <A [k]) A [k] = C ;}} if (A [4]> A [1] & A [5]> A [2] & A [6]> A [3]) {ans = (a [4]-A [1]) * (a [5]-A [2]) * (a [6]-A [3]); printf ("case % d: % d \ n", I, ANS);} else printf ("case % d: 0 \ n", I);} return 0 ;} </span>