HDU 6354 Everything Has Changed 圆相交 模板水题

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 int N=1e5+5;
typedef long long ll;
const int mod=1e9+7;
const double PI=acos(-1.0);
int main()
{
    int t,m;
    double R,ans;
    cin >>  t;
    while(t--)
    {
        cin >> m >> R;
        ans=2*PI*R;
        while(m--)
        {
            int a,b,r;
            cin >> a >> b >> r;
            double d=sqrt(a*a+b*b);                //判断圆与圆的关系
            if(d<abs(R-r)||d>=R+r) continue;
            if(fabs(d -abs(R - r)) <= 1e-9) ans+=PI*r*2;
            else
            {
                double a1,a2;
                a1=acos((r*r+d*d-R*R)/(r*2.0*d));  //计算圆心角的一半
                a2=acos((R*R+d*d-r*r)/(R*2.0*d));
                ans+=a1*2*r-a2*2*R;
            }
        }
        printf("%.8lf\n",ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/deepseazbw/article/details/81474785
今日推荐