Tuesday, May 3, 2011

10991 - Region


#include<iostream>
#include<cstdlib>
#include<cmath>
#include<cstdio>
#define PI 2.0*acos(0.0)
using namespace std;
int main()
{
    unsigned long int t,i;
    long double r1,r2,r3,a,b,c,A,B,C,s,G,TA,CA;
    //freopen("in.txt","r",stdin);
    cin>>t;
    for(i=1;i<=t;i++)
    {
        cin>>r1>>r2>>r3;
        a=r2+r3,b=r1+r3,c=r1+r2;
        s=(a+b+c)/2.0;
        TA=sqrt(s*(s-a)*(s-b)*(s-c));//Triangle area

        //Angle of the triangle at 3 centers of the circle
        A=acos((b*b+c*c-a*a)/(2*b*c));
        B=acos((a*a+c*c-b*b)/(2*a*c));
        C=PI-A-B;

        //Area within circle
        CA=(A*r1*r1+B*r2*r2+C*r3*r3)/2.0;

        //Shaded area
        G=TA-CA;
        printf("%0.6Lf\n",G);
    }
    exit(0);
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.