HDU6354-Everything Has Changed-2018年多校训练赛

Everything Has Changed

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

 

 思路

这道题打眼一看这多英文加上这个图会觉得很难,但是细细的读完题目,就知道这个题目不难,是一个数学几何问题。

这个题就是有多个小圆和大圆相交,求红色的长度。首先,我们需要加个判断,内切和外切的情况,我们不予处理,题上又说相邻小圆之间不会相交,那么我们只用考虑单个小圆与大圆的相交情况。

 

计算弧长公式,我们可以用L=α(弧度)× r(半径) 这个公式来进行计算。那我们利用余弦定理求出大圆和小圆各自弧所对应弧度,这样就得到了两个弧长。用总的减去大圆所对应的弧长,加上小圆所对应的弧长。

 

代码

#include<cstdio>
#include<cmath>

using namespace std;

const double PI=acos(-1.0);

double R,res;

void solve(double x,double y,double r){
    res -= R*2.0*acos((x*x+y*y+R*R-r*r)/(2.0*sqrt(x*x+y*y)*R));
    res += r*2.0*acos((x*x+y*y+r*r-R*R)/(2.0*sqrt(x*x+y*y)*r));
}

bool check(double x,double y,double r){
    if(x*x+y*y>(R+r)*(R+r)) return false;
    if(x*x+y*y<(R-r)*(R-r)) return false;
    return true;
}

int main(){

    int t,m;
    scanf("%d",&t);

    while(t--){
        double x,y,r;
        scanf("%d%lf",&m,&R);

        res = 2.0*PI*R;

        for(int i=0;i<m;i++){
            scanf("%lf%lf%lf",&x,&y,&r);

            if(check(x,y,r)){//判断是否为相交
                solve(x,y,r);
            }

        }
        printf("%.10f\n",res);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Honyelchak

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值