HDU 6354 - Everything Has Changed(计算几何)

Everything Has Changed

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

扫描二维码关注公众号,回复: 2616271 查看本文章

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

 

Source

2018 Multi-University Training Contest 5

#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define clr(a) memset(a,0,sizeof(a))

const int MAXN = 1e5+10;
const int INF = 0x3f3f3f3f;
const int N = 1010;
const double pi = acos(-1.0);
struct node{
    double x,y,r;
    double dis ;
    int flag ;
}p[MAXN];
int t,n;
double R ;

int main(){
    scanf("%d",&t);
    while(t--){
        clr(p);
        scanf("%d%lf",&n,&R);
        double C = (double)(2 * pi * R);
        for(int i=0;i<n;i++){
            scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].r);
            p[i].dis = sqrt((p[i].x * p[i].x + p[i].y * p[i].y));
            if(p[i].dis + p[i].r < R|| p[i].dis - p[i].r == R ||p[i].dis > p[i].r + R)    
                p[i].flag = -1;
            else if(p[i].dis + p[i].r == R )  p[i].flag = 0;
            else  p[i].flag = 1;
        }
        for(int i=0;i<n;i++){
            if(p[i].flag == -1) continue;
            else if(p[i].flag == 0) C += (2.0 * pi * p[i].r);
            else{
                double k = (R * R - p[i].r * p[i].r) / (p[i].dis);
                double u = (k + p[i].dis) / 2.0;
                double v = p[i].dis - u;
                double cost = v / p[i].r;
                double tes = acos(cost) * 2;
                double c1 = tes * p[i].r;
                C += c1;
                cost = u / R;
                tes = acos(cost) * 2;
                c1 = tes * R;
                C -= c1;
            }
        }
        printf("%.8lf\n",C);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/l18339702017/article/details/81474892
今日推荐