hdu6354 Everything Has Changed 几何题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xxxslinyue/article/details/81459848

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;
const double PI = acos(-1);
struct cir {
	int x;
	int r;
	int y;
} a[50000];
double _distance(cir a,cir b) {
	return 1.0*sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double _cos(double a,double b,double c) {
	return 1.0*(a*a+b*b-c*c)/(2*a*b);
}
int N;
double R;
int main() {
	int t;
	cin>>t;
	while(t--) {
		cin>>N>>R;
		cir m;
		m.x=m.y=0;
		m.r=R;
		//cout<<PI<<endl;
		double ans=2*PI*R;
		for(int i=0; i<N; i++) scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].r);
		for(int i=0; i<N; i++) {
			if(_distance(a[i],m)+a[i].r<R||_distance(a[i],m)>=R+a[i].r) {
				// cout<<_distance(a[i],m)<<" "<<a[i].r<<endl;
				continue;
			}
			if(fabs(_distance(a[i],m)+a[i].r-R)<1e-6) {
				ans+=(2*PI*a[i].r);
			} else {
				// cout<<"22"<<endl;
				double r1=_distance(a[i],m);
				double cos_x = _cos(R,r1,a[i].r);
				double x_h = acos(cos_x);
				x_h*=2;
				x_h*=180;
				x_h/=PI;
				double h_R = (1.0*x_h/360)*(2*PI*R);

				double cos_y =_cos(r1,a[i].r,R);
				double y_h = acos(cos_y);
				y_h*=2;
				y_h*=180;
				y_h/=PI;
				double h_r = (1.0*y_h/360)*(2*PI*a[i].r);
				ans+=(h_r-h_R);

			}
		}

		printf("%.8lf\n",ans);


	}
}

猜你喜欢

转载自blog.csdn.net/xxxslinyue/article/details/81459848
今日推荐