zoukankan      html  css  js  c++  java
  • 站军姿

    题目大意:
    给出x1 ,y1 ,r1 ,x2 ,y2 ,r2,代表两个圆。
    计算两个圆覆盖的面积。
    重叠时,ans=S圆-S扇+S三角形。

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #define P(x) (x)*(x)
    #define Pai 3.1415926 
    using namespace std;
    int T;
    double X1,Y1,r1,X2,Y2,r2,ans;
    double work()
    {
        double a,d,cos1,cos2,sin1,sin2,s1,s2,c1,c2;
        d=sqrt(P(X1-X2)+P(Y1-Y2));
        //cout<<d<<endl;
        a=Pai*r1*r1+Pai*r2*r2;
        if(d>=r1+r2) return a;
        else if(d>fabs(r1-r2))//fabs! 
        {
            cos1=(r1*r1+d*d-r2*r2)/(2*r1*d);//加括号 !
            sin1=sqrt(1.0-cos1*cos1); 
            s1=r1*d*sin1;//两三角型面积
            c1=2*acos(cos1);//1 
            cos2=(r2*r2+d*d-r1*r1)/(2*r2*d);
            c2=2*acos(cos2);//2
            s2=c1*(r1*r1)*0.5+c2*(r2*r2)*0.5; 
            a=a+s1-s2;
            return a;
        }
        else 
        {
            s1=Pai*r1*r1,s2=Pai*r2*r2;
            if(s1>s2) return s1;
            return s2;
        }
    }
    int main()
    {
        freopen("standing.in","r",stdin);
        freopen("standing.out","w",stdout);
        scanf("%d",&T);
        while(T--)
        {
            scanf("%lf%lf%lf%lf%lf%lf",&X1,&Y1,&r1,&X2,&Y2,&r2);
            ans=work();
            printf("%.3lf
    ",ans);
        }
        return 0;
    }
    /*
    1
    2.195557 0.030036 2.312310 0.103272 0.535228 2.109461
    */
    
  • 相关阅读:
    A. Difference Row
    B. Fixed Points
    命运
    Climbing Worm
    大学感想
    Constructing Roads
    lintcode605- Sequence Reconstruction- medium- airbnb google
    lintcode616- Course Schedule II- medium
    lintcode615- Course Schedule- medium
    lintcode127- Topological Sorting- medium
  • 原文地址:https://www.cnblogs.com/dfsac/p/7587789.html
Copyright © 2011-2022 走看看