#P4515. Inverted Triangle Area Calculation
Inverted Triangle Area Calculation
Inverted Triangle Area Calculation
Mirko and Slavko are testing an LED display whose pixels are initially white. In each of the N steps, Mirko attaches three electrodes to form a right isosceles triangle. Each triangle has its right angle located at the bottom-left, with the two legs parallel to the coordinate axes. When a triangle is attached, all pixels inside the triangle are inverted (white becomes black and black becomes white). Thus, if a pixel is covered by an odd number of triangles, it ends up black; if covered by an even number, it remains white.
A point \((X,Y)\) is inside a triangle with right-angle vertex at \((x,y)\) and leg length \(L\) if and only if \[ X \ge x, \quad Y \ge y, \quad (X - x) + (Y - y) \le L. \]
Given \(N\) triangles with their right-angle vertex coordinates and leg lengths, compute the total area for which the pixels are black (i.e. the area covered by an odd number of triangles). The triangles may overlap, and the coverage parity determines the final color.
inputFormat
The first line contains a single integer \(N\), the number of triangles.
Each of the next \(N\) lines contains three integers \(x\), \(y\), and \(L\), where \((x, y)\) is the coordinate of the right-angle (bottom-left) vertex of the triangle and \(L\) is the leg length.
outputFormat
Output a single floating-point number representing the total area of black pixels. The result should be printed with one decimal place of precision.
sample
1
0 0 10
50.0