hdu6354(数学)

Everything Has Changed

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 198    Accepted Submission(s): 96
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

题意:有一个圆形,中心点(0,0),半径R;它是一个大圆盘,现在切割师傅要切m个圆,中心(x,y),半径r;

保证两圆不会相交。若切的圆在大圆里面,不相交,则不计算。求切割完后的周长。图纸中的图形,就是求红色的周长,绿色的不计算。

解析:

#include<bits/stdc++.h>
using namespace std;

#define e exp(1)
#define pi acos(-1)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define mem(a,b) memset(a,b,sizeof(a))
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
	int T;scanf("%d",&T);
	while(T--)
	{
		int m,R;scanf("%d%d",&m,&R);
		double sum=2*pi*R;
		while(m--)
		{
			int x,y,r;scanf("%d%d%d",&x,&y,&r);
			double d=x*x+y*y;
			
			double s1=(R-r)*(R-r);
			double s2=(R+r)*(R+r);
			if(d==s1)
			{
				sum+=2*pi*r*1.0;
			}
			else if(s1<d&&d<s2)
			{
				sum-=acos( (R*R+d-r*r)*1.0/(2*R*sqrt(d)) )*2*R;
				sum+=acos( (r*r+d-R*R)*1.0/(2*r*sqrt(d)) )*2*r;
			}
		}
		printf("%.7lf\n",sum);
	}
	return 0;
	
} 

猜你喜欢

转载自blog.csdn.net/yu121380/article/details/81460067
今日推荐