zoukankan      html  css  js  c++  java
  • 6354 Everything Has Changed

    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 106.
    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
     
    
    Recommend
    chendu   |   We have carefully selected several similar problems for you:  6396 6395 6394 6393 6392 
     

    板子题,注意内切要算。以及判断优劣弧的时候。用距离或者是弦的左右来判断。

    我写的时候对优劣弧的定义弄反了,没改。我用的距离判断。

    #include <math.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #define eps 1e-9
    #define pi acos(-1.0)
    struct point
    {
        double x,y;
    };
    struct yuan
    {
        point a;
        double r;
    };
    typedef struct point point;
    double xmult(point p1,point p2,point p0)
    {
        return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
    }
    double distance(point p1,point p2)
    {
        return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
    }
    //点到直线的距离
    double disptoline(point p,point l1,point l2)
    {
        return fabs(xmult(p,l1,l2))/distance(l1,l2);
    }
    //求两直线交点
    point intersection(point u1,point u2,point v1,point v2)
    {
        point ret=u1;
        double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))
        /((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
        ret.x+=(u2.x-u1.x)*t;
        ret.y+=(u2.y-u1.y)*t;
        return ret;
    }
    int intersect_circle_circle(point c1,double r1,point c2,double r2)
    {
        return distance(c1,c2)<r1+r2&&distance(c1,c2)>fabs(r1-r2);
    }
    void intersection_line_circle(point c,double r,point l1,point l2,point& p1,point& p2)
    {
        point p=c;
        double t;
        p.x+=l1.y-l2.y;
        p.y+=l2.x-l1.x;
        p=intersection(p,c,l1,l2);
        t=sqrt(r*r-distance(p,c)*distance(p,c))/distance(l1,l2);
        p1.x=p.x+(l2.x-l1.x)*t;
        p1.y=p.y+(l2.y-l1.y)*t;
        p2.x=p.x-(l2.x-l1.x)*t;
        p2.y=p.y-(l2.y-l1.y)*t;
    }
    void intersection_circle_circle(point c1,double r1,point c2,double r2,point& p1,point& p2)
    {
        point u,v;
        double t;
        t=(1+(r1*r1-r2*r2)/distance(c1,c2)/distance(c1,c2))/2;
        u.x=c1.x+(c2.x-c1.x)*t;
        u.y=c1.y+(c2.y-c1.y)*t;
        v.x=u.x+c1.y-c2.y;
        v.y=u.y-c1.x+c2.x;
        intersection_line_circle(c1,r1,u,v,p1,p2);
    }//两圆的交点
    double simahdu(point a, point b,point c,double r)
    {
        double d=distance(a,b)*0.5;
        double pp= 2*asin(d/r)*r;
        return pp;
    }
    int main()
    {
        int T;
        scanf("%d",&T);
        while(T--)
        {
            int n;
            double r;
            scanf("%d%lf",&n,&r);
            point ww;
            ww.x=0;ww.y=0;
            double ans=2.0*pi*r;
            for(int i=1;i<=n;i++)
            {
                point qq;
                double qr;
                scanf("%lf%lf%lf",&qq.x,&qq.y,&qr);
                int ppp= intersect_circle_circle(ww,r,qq,qr);
                if(distance(qq,ww)==fabs(qr-r))
                {
                    ans=ans+2*pi*qr;
                }
                if(ppp==1)
                {
                    point  jiao1,jiao2;
                    intersection_circle_circle(qq,qr,ww,r,jiao1,jiao2);
                    point zd;
                    zd.x=(jiao1.x+jiao2.x)/2;
                    zd.y=(jiao1.y+jiao2.y)/2;
                    double l1=distance(ww,qq);
                    double l2=distance(ww,zd);
                    double l3=distance(qq,zd);
                    double jiayou=simahdu(jiao1,jiao2,qq,qr);
                    double jialie=2.0*pi*qr-jiayou;
                    double jianyou=simahdu(jiao1,jiao2,ww,r);
                    double jianlie=2.0*pi*r-jianyou;
                    if(l1>l2 && l1>l3)//加优减优
                    {
                        ans=ans+jiayou-jianyou;
                        
                    }
                    else if(l3 > l2)//加优减劣
                    {
                        ans=ans+jiayou-jianlie;
                    }
                    else//加劣减优
                    {
                        ans=ans+jialie-jianyou;
                        
                    }
                        
                    
                    
                }
                else
                {
                    continue;
                }
                
            }
            printf("%0.20lf
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    字符串、列表(操作)
    数据类型
    第二周 第四部分
    第二周 第三部分
    第二周第二部分
    特征缩放和标准化 设置学习率大小 正则方程
    梯度下降 coursera.org
    监督学习和无监督学习
    手写数字问题
    pytorch基础
  • 原文地址:https://www.cnblogs.com/2014slx/p/9475140.html
Copyright © 2011-2022 走看看