#P4406. Union of Triangles Area
Union of Triangles Area
Union of Triangles Area
Given n triangles, compute the area of their union. Each triangle is defined by its three vertices in the 2D plane. In this problem, it is guaranteed that the triangles do not overlap (they might only touch at the boundaries), so the union area is equal to the sum of the areas of the individual triangles.
The area A of a triangle with vertices (x₁, y₁), (x₂, y₂) and (x₃, y₃) is given by:
\( A = \frac{1}{2} \left| x_1(y_2 - y_3) + x_2(y_3 - y_1) + x_3(y_1 - y_2) \right| \)
inputFormat
The first line contains a single integer n (1 ≤ n ≤ 100), denoting the number of triangles. Each of the following n lines contains 6 space-separated numbers: x₁ y₁ x₂ y₂ x₃ y₃, representing the coordinates of the three vertices of a triangle. All coordinates are integers and their absolute values do not exceed 104.
outputFormat
Print a single line containing the area of the union of the given triangles. The answer will be considered correct if its absolute or relative error does not exceed 10-6.
sample
1
0 0 0 1 1 0
0.500000