2018 Multi-University Training Contest 5 E Everything Has Changed

                                     Everything Has Changed

                         Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
                                                Total Submission(s): 3444    Accepted Submission(s): 909
                                                                                  Special Judge

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

思路:据题意可以知道在母圆内的和在母圆外且不于母圆相交的可以忽略,并且子圆互不相交。所以我们用余弦定理 c^2=a^2+b^2-2abcos(γ)  (γ为角C) 可以求出母圆和子圆相交的周长的角度,求出角度自然就可以求出增加和减少的周长了。

#include<bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int main(){
	int t,m,R,x,y,r;
	scanf("%d",&t);
	while(t--){
		scanf("%d%d",&m,&R);
		double jiao=pi;
		double ans=0;
		while(m--){
			scanf("%d%d%d",&x,&y,&r);			
			int dis=x*x+y*y;
			double ddis=sqrtl(x*x+y*y);
			if(dis>(R+r)*(R+r)||dis<(R-r)*(R-r)) continue;//子圆在母圆内或者不与母圆相交
			double ang1=acos((R*R+dis-r*r)/(2*R*ddis));
			double ang2=acos((r*r+dis-R*R)/(2*r*ddis));
			jiao-=ang1;
			ans+=ang2*2*r;
		}
		ans+=2*R*jiao;
		printf("%.20f\n",ans);
	}
} 

...简单的几何

猜你喜欢

转载自blog.csdn.net/weixin_40800935/article/details/81479732
今日推荐