Encircling Circles
Time limit1sMemory limit128 MB
Given n circles and a radius r, find the length of the boundary of the union of all radius-r circles that enclose every given circle.
- Level
Medium7 of 10
- Topics
- Geometry, Math, Implementation, Brute force
- Solved
- No attempts yet
Problem
You are given a set of circles with various radii placed at various positions on the plane; the circles may overlap one another. If a circle of radius is placed at a suitable position and is large enough, that circle can completely enclose every circle in .
There may be more than one position at which a circle of radius encloses all circles of . Let be the union of the areas covered by the enclosing circles over all such positions. In other words, for every point in there exists at least one circle of radius that encloses both that point and every circle of . Your task is to compute the length of the boundary of region .
Figure I.1 shows an example of the set and the region . The three solid circles belong to , the dashed circles show some of the possible positions of the enclosing circle, and the thick dashed closed curve bounds the region .

Figure I.1: Example of the Circle Set
Input
The input is a sequence of datasets. The number of datasets is less than . Each dataset has the following format.
n r
x1 y1 r1
x2 y2 r2
...
xn yn rn
The first line of a dataset contains two positive integers and separated by a single space. is the number of circles in and does not exceed ; is the radius of the enclosing circle and does not exceed .
Each of the following lines contains three integers separated by single spaces. is the center of the -th circle of and is its radius. You may assume , , and .
The end of the input is indicated by a line containing two zeros separated by a single space.
Output
For each dataset, output on one line the length of the boundary of region , rounded to exactly two digits after the decimal point (for example, 81.68). If is too small to enclose every circle in (that is, no valid position exists), output a line containing only 0.00. Output nothing else.
The inputs are chosen so that the rounded value is unambiguous.
Hint

Figure I.2: An illustration of the last dataset