Mandalas
Time limit1sMemory limit128 MB
Given up to 500 circles, count how many regions the arrangement of circles divides the plane into, handling tangency and duplicate circles exactly.
- Level
Medium7 of 10
- Topics
- Geometry, Graph, Implementation, Math
- Solved
- No attempts yet
Problem
Shasita is drawing mandalas. First she draws several circles, and then she colours the regions that they divide the plane into.
Her younger sister Rice agrees to help: Rice will draw the circles and Shasita will colour them. Shasita does not want to colour a huge number of tiny regions, so she wants to fix in advance how many regions the circles will create. Rice, however, is not good at counting regions, so she asks you for help.
Given a mandala, that is, an arrangement of circles, determine how many regions it divides the plane into.
Input
The first line contains the number of test cases. Each test case has the following format:
- one line with the integer (), the number of circles;
- lines follow, each with three integers , , describing the -th circle, whose centre is and whose radius is , with and .
Output
For each test case, output a single integer on its own line: the number of regions into which the circles divide the plane .