hdu Everything Has Changed

                             

               Everything Has Changed

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

 

思路:俩圆有俩种情况,一是俩圆相交,二是俩圆内切;

相交的条件是圆心距离小于俩圆半径的和,大于俩圆半径的差;R-r<d<R+r, 需要加绝对值fabs(R-r)

内切的条件是圆心距离等于俩圆半径的和;d=R-r,需要加绝对值fabs(R-r)

求圆心角需要用的余弦定理和反三角函数acos,求出的圆心角是弧度制,求弧长是圆心角乘以半径

 

#include<bits/stdc++.h>
using namespace std;
#define PI acos(-1.0)
struct yuan
{
    double x,y,r;
    int flag;
    double d;
} a[1005];
int main()
{
    int t;
    scanf("%d",&t);
    int n;
    double m;
    while(t--)
    {
        scanf("%d%lf",&n,&m);
        double L=2*PI*m;
        for(int i=0; i<n; i++)
        {
            scanf("%lf%lf%lf",&a[i].x,&a[i].y,&a[i].r);
            a[i].d=sqrt(a[i].x*a[i].x+a[i].y*a[i].y);
            if((a[i].d<(m+a[i].r))&&(a[i].d>fabs(m-a[i].r)))
            {
                a[i].flag=0;
            }
            else if(a[i].d==fabs(m-a[i].r))
            {
               a[i].flag=1;
            }
            else
            {
                a[i].flag=2;
            }
        }

        for(int i=0;i<n;i++)
        {
            if(a[i].flag==0)
            {
                double a1=2*acos((a[i].r*a[i].r+a[i].d*a[i].d-m*m)/(2*a[i].d*a[i].r));
                double a2=2*acos((m*m+a[i].d*a[i].d-a[i].r*a[i].r)/(2*a[i].d*m));
                double s1=(a1)*a[i].r;
                double s2=a2*m;
                L+=s1-s2;

            }
            if(a[i].flag==1)
            {
                L+=a[i].r*2*PI;

            }
            else
                continue;
        }
        printf("%lf\n",L);

    }
}


也不需要结构体,一个for循环也可以

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值