Everything Has Changed
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 765 Accepted Submission(s): 445
Special JudgeProblem 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
Source
题意:
给你一个圆心为(0,0)的大圆半径,和一堆圆的圆心坐标和直径,让你求出内切圆与相交圆的周长。如图红色求,绿色不求。
题解:
直接模拟就好,分成三种情况,内含的直接不要,内切的直接加上小圆周长,相交的用余弦公式求出大小圆圆心角,分别乘以半径即可算出弧长。
注意函数acos()返回的是弧度制,不是角度制。
#include<bits/stdc++.h>
using namespace std;
#define po(a) pow(a,2)
const double pi = acos(-1.0);
struct node {
int x,y,r;
double pre,dis;
} num[1000005];
double dis(int x0,int y0,int x1,int y1) {
return sqrt(pow((x0-x1),2) + pow((y0-y1),2));
}
int main() {
int _;
int xr,yr,R,n;
double Rdis,Rper,ans;
for(cin>>_; _; _--) {
scanf("%d %d",&n,&R);
ans = 2*pi*R;
for(int i = 0; i < n; i++) {
scanf("%d %d %d",&num[i].x,&num[i].y,&num[i].r);
num[i].pre = 2 * pi * num[i].r;
num[i].dis = dis(num[i].x,num[i].y,0,0);
if(num[i].dis + num[i].r < R) {
continue;
} else if(num[i].dis + num[i].r == R ) {
ans += num[i].pre;
} else if((num[i].dis<=R&&num[i].dis+num[i].r>=R)||(num[i].dis>=R&&num[i].dis-num[i].r<=R)) {
ans -= R * 2 * acos((po(num[i].dis)+po(R)-po(num[i].r)) / (2*R*num[i].dis));
ans += num[i].r * 2 * acos((po(num[i].dis)+po(num[i].r)-po(R)) / (2 * num[i].r *num[i].dis));
}
}
printf("%.20lf\n",ans);
}
}