HDU 6354 Everything Has Changed (多校水题)

hdu 6354

题目:

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的圆, 然后给出n个圆的原点和半径, 每个若是和原点圆相交就相当于割去这个原点圆相交的部分, 求解原点圆最后剩下的图形的周长(题目保证只有原点圆会和其他圆相交)。

题解:大大的水题。。。竟然没人做。通过给定圆的圆心可以确定原点圆与另外圆的圆心距, 通过判断圆心距可以与两圆半径的关系可以知道两圆的相交情况。

(1). 圆心距  >= 两圆半径和, 两圆相离结果不改变。

(2). 圆心距 < 两圆半径差, 大圆包含小圆, 外部周长不改变。

(3). 圆心距 == 两圆半径差 并且原点圆半径大于等于另一圆半径,此时两圆内切, 周长增加值为小圆周长。

(4). 圆心距 < 两圆半径和 且 大于两圆半径差。此时两圆相交, 连接两圆圆心在通过一个交点构成圆心三角形, 三角形中R r是其中两边, 第三边是两圆圆心距通过两点距离求出, 这样可以计算出角度进而得知圆心角可以计算相交部分的周长。减掉原点圆弧的加上另一个圆的弧就可以了。(高考就是送分题)

AC代码:

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
    int T, i, j, m, n, ans;
    double R, x, y, r, len, c;
    double Pi = acos(-1.0);
    scanf("%d", &T);
    while(T--){
        scanf("%d %lf", &m, &R);
        c = Pi * R * 2;
        while(m--){
            scanf("%lf %lf %lf", &x, &y, &r);
            len = sqrt(x * x + y * y);
            if(len >= (r + R))
                continue;
            else if(len > fabs(R - r))
                c = c + r * 2 * acos((len * len + r * r - R * R) / (2.0 * len * r)) - R * 2 * acos((R * R + len * len - r * r) / (2.0 * R * len));
            else if(len == fabs(R - r) && R >= r)
                c += 2 * Pi * r;
        }
        printf("%.20f\n", c);
    }
    return 0;
}

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值