Simi Circles
InterviewTime limit1sMemory limit1024 MB
Given circles where each one overlaps only its neighbors in the list, find the total area their union covers in each scenario.
- Level
Medium4 of 10
- Topics
- Geometry, Math, Implementation
- Solved
- No attempts yet
Problem
Arup has a step-daughter, Simi, at home, so he is often in charge when she swims with her friends. When she finishes, Simi runs into the house without fully drying herself. As she hurries through the house to the bathroom, she leaves water drops on the floor.
Arup's wife, Anita, blames him for not watching the kids closely and making sure they dried off before entering. Anita says the wood was ruined by water damage. Arup knows that not all of the wood is ruined, so he only wants to take responsibility for the area of the wood floor that has water on it.
When Simi runs through the house, each drop hits the ground and forms a perfect circle. She runs fast enough that each drop intersects at most the previous drop and no others. Sometimes a drop does not intersect the previous drop at all. So each drop can intersect at most two drops: the one before it and the one after it. Each drop (circle) covers some area of the wood floor. No circle is completely covered by another circle.
Given a list of circles, where each circle may only intersect the previous circle and the next circle in the list, find the total area covered by all the circles.
Input
The first line contains a single positive integer (), the number of Simi circle scenarios. Each scenario follows.
The first line of each scenario contains a single integer (), the number of drops in that scenario. The next lines describe the drops in the order they occurred, one drop per line. Each line contains exactly three real numbers separated by single spaces: (), (), and (). These are the x and y coordinates of the drop's center (in cm) and the drop's radius (in cm).
Output
For each scenario, print Set #i: where is the scenario number starting at 1, followed by the total area covered by all the drops, as a positive real number rounded to 2 decimal places, in cm^2. For example, an area of 31.674 cm^2 is printed as 31.67, and an area of 31.675 cm^2 is printed as 31.68.
Print a blank line after the output for each scenario. Follow the format shown in the sample output.
Hint
If you need in your program, use the value 3.1415926535898.