zoukankan      html  css  js  c++  java
  • Everything Has Changed(求圆周长)

    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)(0,0) and radius RR. Then, mm mechanical arms will cut and erase everything within its area of influence simultaneously, the ii-th area of which is a circle with center coordinates (xi,yi)(xi,yi) and radius riri (i=1,2,,m)(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 TT, indicating the number of test cases. 
    The following lines describe all the test cases. For each test case: 
    The first line contains two integers mm and RR. 
    The ii-th line of the following mm lines contains three integers xi,yixi,yi and riri, indicating a cutting area. 
    1T10001≤T≤1000, 1m1001≤m≤100, 1000xi,yi1000−1000≤xi,yi≤1000, 1R,ri10001≤R,ri≤1000 (i=1,2,,m)(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 10610−6. 
    Formally, let your answer be aa and the jury's answer be bb. Your answer is considered correct if |ab|max(1,|b|)106|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
     
    题意:求红色边边的周长,绿色不算。
    1/相交的时候 减去与相交的大圆的边长,加上相交的小圆的在大圆内的边长
    2/内切的时候 只需要加上小圆的面积
    仔细读题啊////翻译成面积没脸了
     
    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    #include <iostream>
    #define PI acos(-1)
    using namespace std;
    int main(){
        int t,m,R;
        cin>>t;
        while(t--){
            cin>>m>>R;
            double x,y,r,l,h,ans=0;
            ans = 2.0*PI*R;
            for(int i=0;i<m;i++)
            {
                cin>>x>>y>>r;
                l = sqrt(x*x+y*y);
                if(l == R-r)//内切
                {
                    ans+=2.0*PI*r;
                }
                else if(l == R+r || l < R-r)//外切或内含
                {
                    ans+=0;
                }
                else if(l > R-r && l < R+r)//相交
                {
                    if(l >= R){//小圆圆心在大圆外
                        h = (R*R+l*l-r*r)/(2.0*l);
                        ans-=2.0*R*acos(h/R);
                        ans+=2.0*r*acos((l-h)/r);
                    }
                    else{//小圆圆心在大圆外
                        h = (R*R-r*r-l*l)/(2.0*l);
                        ans-=2.0*R*acos((h+l)/R);
                        ans+=2*PI*r-2.0*r*acos(h/r);
                    }
                }
            }
            printf("%.20lf
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    Spark Shuffle FetchFailedException解决方案
    Spark常见问题汇总
    网络表示学习介绍
    Graph Embedding: metapath2vec算法
    spark参数介绍
    spark文章
    集群运行Spark程序实例讲解
    基于Spark UI性能优化与调试——初级篇
    Spark Shuffle FetchFailedException
    没有指针的java语言
  • 原文地址:https://www.cnblogs.com/LLLAIH/p/10800510.html
Copyright © 2011-2022 走看看