Everything Has Changed HDU - 6354

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)(0,0) and radius RR . Then, mm mechanical arms will cut and erase everything within its area of influence simultaneously, the ii -th area of which is a circle with center coordinates (xi,yi)(xi,yi) and radius riri (i=1,2,⋯,m)(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 TT , indicating the number of test cases.
The following lines describe all the test cases. For each test case:
The first line contains two integers mm and RR .
The ii -th line of the following mm lines contains three integers xi,yixi,yi and riri , indicating a cutting area.
1≤T≤10001≤T≤1000 , 1≤m≤1001≤m≤100 , −1000≤xi,yi≤1000−1000≤xi,yi≤1000 , 1≤R,ri≤10001≤R,ri≤1000 (i=1,2,⋯,m)(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−610−6 .
Formally, let your answer be aa and the jury's answer be bb . Your answer is considered correct if |a−b|max(1,|b|)≤10−6|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

思路:用acos(double(R*R + d * d - r * r) / (2 * R*d));求出他的角,然后用弧长公式l = r*c;求出弧长。

分析:两圆的情况。

/*
如题三种情况
1.两圆相交圆心距大于两圆半径之和小于两元半径之差,
此时只需减去原来的加上增加的即可。
2.两圆内切。半径只需加上增加的圆的周长即可。
3.内含和两圆相离和外切时两圆无关,周长不增不减。
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
const int maxn = 1100;
int T, m, R, x, y, r;
double c1, c2;
const double PI = acos(-1.0);
/*
如题三种情况
1.两圆相交圆心距大于两圆半径之和小于两元半径之差,
此时只需减去原来的加上增加的即可。
2.两圆内切。半径只需加上增加的圆的周长即可。
3.内含和两圆相离和外切时两圆无关,周长不增不减。
*/
int main()
{
	scanf("%d", &T);
	while (T--)
	{
		//cin >> m >> R;
		scanf("%d%d", &m, &R);
		double C = 2 * PI*R;
		for (int i = 0; i < m; i++)
		{
			//cin >> x >> y >> r;
			scanf("%d%d%d", &x, &y, &r);
			double d = sqrt(double(x*x + y * y));
			if (d < R + r && d > abs(R - r))
			{
				c1 = 2.0*acos(double(R*R + d * d - r * r) / (2 * R*d));
				c2 = 2.0*acos(double(r * r + d * d -R*R ) / (2 * r*d));
				C -= c1 * R;
				C += c2 * r;
			}
			else if (d == abs(R - r))
			{
				C += 2 * PI * r;
			}
		}
		printf("%lf\n", C);
	}
	return 0;
}

扫描二维码关注公众号,回复: 2765422 查看本文章

猜你喜欢

转载自blog.csdn.net/fighting_yifeng/article/details/81611158
今日推荐