Edward is a worker for Aluminum Cyclic Machinery. His work is operating mechanical arms to cut out designed models. Here is a brief introduction to 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 .
Example
Input
1
4 10
6 3 5
10 -4 3
-2 -4 4
0 9 1
Output
81.62198908430238475376
Tips
1.求被截圆的剩余周长,分别判断两个圆是相切,相离还是相交
2.用c++的反三角函数和余弦定理求角度(注意角度是弧度值),弧度乘以圆半径就是周长
#include<bits/stdc++.h>
using namespace std;
const double pi = 3.141592654;
struct E{
double x,y;
}e1,e2;
double dis(E a,E b){
return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}
int main() {
int t;cin>>t;
while(t--){
int n=0,rr=0;cin>>n>>rr;
double sum=2.0*pi*rr;
for( int i=0; i<n; i++ ){
double r1=rr,r2=0,dist=0;
e1.x=0;e1.y=0;cin>>e2.x>>e2.y>>r2;dist=dis(e1,e2);
if(dist+r2==r1) sum+=2*pi*r2;
else if(dist<r1-r2) continue;
else if(dist>=r1-r2&&dist<r1+r2){
sum+=acos((pow(r2,2)+pow(dist,2)-pow(r1,2))/(2*r2*dist))*2.0*r2;
sum-=acos((pow(r1,2)+pow(dist,2)-pow(r2,2))/(2*r1*dist))*2.0*r1;
}
}
printf("%.20f\n",sum);
}
return 0;
}