Everything Has Changed
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
Special Judge
Problem Description
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
代码:
#include <bits/stdc++.h>
using namespace std;
typedef double DB;
DB eps=1E-7;
DB PI=acos(-1.0);
DB Circumference(DB x1,DB y1,DB r1,DB x2,DB y2,DB r2){ //一个圆被另一个切去一部分剩余的周长
double d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
if((r1-r2)>=d-eps&&(r1-r2)<=d+eps){
return 2*PI*r2;
}
else if(d>=r1+r2-eps||d<=r1-r2+eps)
return 0;
else{
double a1=2*acos((r1*r1+d*d-r2*r2)/2/r1/d); //第一个圆的圆心角
double a2=2*acos((r2*r2+d*d-r1*r1)/2/r2/d); //第二个圆的圆心角
double ans=r2*a2-r1*a1; //第一个圆的弧长减去第二个
return ans;
}
}
int main(){
int m;
double t,R;
double x1,y1,r1,x2,y2,r2;
double ans;
cin>>t;
while(t--){
ans=0;
scanf("%d%lf",&m,&R);
ans=2*PI*R;
for(int i=0;i<m;i++){
cin>>x2>>y2>>r2;
ans+= Circumference(0,0,R,x2,y2,r2);
}
printf("%.11lf\n",ans);
}
return 0;
}