Edward is a worker for Aluminum Cyclic Machinery. His work is operating mechanical arms to cut out designed models. Here is a brief introduction of his work.
Assume the operating plane as a two-dimensional coordinate system. At first, there is a disc with center coordinates (0,0) and radius R. Then, m mechanical arms will cut and erase everything within its area of influence simultaneously, the i-th area of which is a circle with center coordinates (xi,yi) and radius ri (i=1,2,⋯,m). In order to obtain considerable models, it is guaranteed that every two cutting areas have no intersection and no cutting area contains the whole disc.
Your task is to determine the perimeter of the remaining area of the disc excluding internal perimeter.
Here is an illustration of the sample, in which the red curve is counted but the green curve is not.

Input

The first line contains one integer T, indicating the number of test cases.
The following lines describe all the test cases. For each test case:
The first line contains two integers m and R.
The i-th line of the following m lines contains three integers xi,yi and ri, indicating a cutting area.
1≤T≤1000, 1≤m≤100, −1000≤xi,yi≤1000, 1≤R,ri≤1000 (i=1,2,⋯,m).

Output

For each test case, print the perimeter of the remaining area in one line. Your answer is considered correct if its absolute or relative error does not exceed 10−6.
Formally, let your answer be a and the jury’s answer be b. Your answer is considered correct if |a−b|max(1,|b|)≤10−6.

Sample Input

1
4 10
6 3 5
10 -4 3
-2 -4 4
0 9 1

Sample Output

81.62198908430238475376

题意

有一个大圆,被几个小圆切掉了,求剩下的部分周长,内部的不算,只算外面的,和大圆内切也算,即图中的红边。小圆之间相切的不算。

相交部分的周长可用l/r=αl/r=\alpha来计算,余弦定理求出相交部分的圆心角即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double esp = 0.00000001;
inline int Compare(double a, double b)
{
if (fabs(a - b) < esp)
return 0;
if (a < b)
return -1;
return 1;
}
struct point
{
double x, y;
point() {}
point(double a, double b) { x = a; y = b; }
inline double Length() {
return sqrt(x*x + y * y);
}
inline point operator-(point d) {
return point(x - d.x, y - d.y);
}
inline double Dot(point d) { return x * d.x + y * d.y; }
inline double Cross(point d) { return x * d.y - y * d.x; }
};
struct circle
{
point pt;
double r;
circle() {}
circle(double x, double y, double z) { pt = point(x, y); r = z; }
circle(int i) { scanf("%lf%lf%lf", &pt.x, &pt.y, &r); }
inline double Area() {
return PI * r*r;
}
inline bool Intersect(circle C) {
double len = (C.pt - pt).Length();
return Compare(len, (C.r + r)) < 0 && Compare(len, fabs(C.r - r)) > 0;
}
inline bool Inscribe(circle C) {
return Compare((C.pt - pt).Length(), fabs(C.r - r)) == 0;
}
inline bool External_Cutting(circle C) {
return Compare((C.pt - pt).Length(), fabs(C.r + r)) == 0;
}
inline double Perimeter() { return PI * 2 * r; }
inline double solve(circle C) {
if (External_Cutting(C))
return 0.0;
double len = (C.pt - pt).Length();
double ans = 0;
ans -= acos((len*len + r * r - C.r*C.r) / (2 * len*r))*r;
ans += acos((len*len + C.r * C.r - r * r) / (2 * len*C.r))*C.r;
return 2 * ans;
}
};
vector<circle>v;
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
int m, R;
scanf("%d%d", &m, &R);
circle big = circle(0, 0, R);
double ans = big.Perimeter();
v.clear();
for (int i = 0; i < m; i++)
{
v.push_back(circle(i));
}
for (int i = 0; i < v.size(); i++)
{
if (v[i].Inscribe(big))
{
ans += v[i].Perimeter();
}
else if (v[i].Intersect(big))
{
ans += big.solve(v[i]);
}
}
printf("%.10f\n", ans);
}
}