2018 Multi-University Training Contest 5 E( 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

题意:看图中计算红线的长度,不会有小圆重合和连续的内部相切

思路:当内切是长度加圆全周长,外切,相离,在内部为0。下面讨论相交

连接两圆圆心,把两圆相交的交点,分别于两圆心可以发现可以利用余弦定理 c^2=a^2+b^2-2abcos(γ)  (γ为角C)就可以算出

注意arccos在C++内部只会返回大于0的值

代码:

struct node
{
    double x,y,r;
}a[1005];
double R;

int judge(double x,double y,double r)
{
    double w=R+r;
    double t=sqrt((x*x)+(y*y));
    if(t>=w) return 0;
    if(t+r<R) return 0;
    return 1;
}
int main()
{
    int T;
    int m;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%lf",&m,&R);
        double ans=2.0*PI*R;
        for(int i=1;i<=m;i++)
        {
            scanf("%lf%lf%lf",&a[i].x,&a[i].y,&a[i].r);
            if(judge(a[i].x,a[i].y,a[i].r))
            {
                if(sqrt(a[i].x*a[i].x+a[i].y*a[i].y)+a[i].r==R) ans=ans+2*PI*a[i].r;
                else
                {
                    double d=sqrt(a[i].x*a[i].x+a[i].y*a[i].y);
                    double A1=2*acos((d*d+R*R-a[i].r*a[i].r)/(2*d*R));
                    double A2=2*acos((d*d+a[i].r*a[i].r-R*R)/(2*d*a[i].r));
                    ans-=A1*R;
                    ans+=A2*a[i].r;
                    continue;
                }
            }
        }
        printf("%.11lf\n",ans);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值