#P3844. Color Flipping Circles
Color Flipping Circles
Color Flipping Circles
On a 2D plane, there are n circles. Any two distinct circles have only one of the two relationships: either they are disjoint (they may be externally tangent) or one is contained in the other (they may be internally tangent). Initially, the entire plane is colored black. Then, in the given input order, each circle is drawn. When drawing a circle, the color of every point in the region covered by that circle is toggled: black becomes white and white becomes black.
After drawing all the circles, output the total area of all white regions. Mathematically, a point becomes white if and only if it is covered by an odd number of circles. Using the notation, if a point is covered by circles with total count k, it will be white if k is odd and remain black if k is even.
Note that because every two circles are either disjoint or nested, the circles form a tree-like structure. In any chain of nested circles, if the areas of the circles are \(A_1, A_2, A_3, \dots\) from outermost to innermost, then the white portion contributed by that chain is \(A_1 - A_2 + A_3 - \dots\) (i.e. alternating sum of areas). The area of a circle with radius \(r\) is given by \(\pi r^2\) in \(\LaTeX\) format.
inputFormat
The first line contains an integer n
(the number of circles). Each of the following n
lines contains three numbers: x
, y
, and r
, where (x
, y
) is the center of the circle and r
is its radius. All numbers can be assumed to be floating‐point values.
outputFormat
Output a single number: the total white area after drawing all circles. The answer is expected to be printed with a precision of 6 decimal places.
sample
1
0 0 1
3.141593