uva 11731 - Ex-circles

题意:已知三角形ABC的3条边长,求三角形ABC 的面积,以及阴影部分的总面积。















 

#include<iostream>

#include<cstdio>

#include<cmath>

#define sqr(a) ((a)*(a))

#define pi 2.0*asin(1.0)



using namespace std;



typedef struct point

{

    double x,y;

    point(double xx=0,double yy=0):x(xx),y(yy){}

}vector;



vector operator - (point a,point b)

{

    return vector(a.x-b.x,a.y-b.y);

}

point operator + (point a,vector b)

{

    return point(a.x+b.x,a.y+b.y);

}

vector operator * (vector a,double b)

{

    return vector(a.x*b,a.y*b);

}

double dot(vector a,vector b)

{

    return a.x*b.x+a.y*b.y;

}

double cross(vector a,vector b)

{

    return a.x*b.y-a.y*b.x;

}

double len(vector a)

{

    return sqrt(dot(a,a));

}

vector resiz(vector a,double l)

{

    l/=len(a);

    return vector(a.x*l,a.y*l);

}

vector rot(vector a,double rad)

{

    double c=cos(rad),s=sin(rad);

    return vector(a.x*c-a.y*s,a.x*s+a.y*c);

}

point inter(point p,vector v,point q,vector w)

{

    vector u=p-q;

    double t=cross(w,u)/cross(v,w);

    return p+v*t;

}

point f(point o,vector v,point a,vector w,double r,double &rr,double rad)

{

    vector u=resiz(rot(w,pi/2),2*r);

    if(dot(v,u)>0) u=vector(-u.x,-u.y);

    point b=a+u;

    point p=inter(o,v,a,w),q=inter(o,v,b,w);

    rr=len(p-o)/len(q-o)*r;

    double d=rr/sin(rad);

    v=resiz(v,d);

    return o+v;

}



int main()

{

    int i=1;

    double a,b,c,tha,thb,thc;

    double r,r1,r2,r3;

    point pa,pb,pc,p1,p2,p3;

    vector va,vb,vc;

    while(cin>>a>>b>>c && a+b+c)

    {

        tha=(sqr(b)+sqr(c)-sqr(a))/(2*b*c);

        thb=(sqr(a)+sqr(c)-sqr(b))/(2*a*c);

        thc=(sqr(b)+sqr(a)-sqr(c))/(2*b*a);

        tha=acos(tha);

        thb=acos(thb);

        thc=acos(thc);

        vc.x=pa.x+c;

        pb=pa+vc;

        vb=resiz(rot(vc,tha),b);

        pc=pa+vb;

        va=pc-pb;

        r=cross(vc,vb)/(a+b+c);

        p1=f(pa,rot(vc,tha/2),pb,va,r,r1,tha/2);

        p2=f(pb,rot(va,thb/2),pc,vb,r,r2,thb/2);

        p3=f(pc,rot(vb,thc/2-pi),pa,vc,r,r3,thc/2);

        double s1=fabs(cross(p1-p2,p1-p3))/2;

        a=len(p1-p2);

        b=len(p2-p3);

        c=len(p3-p1);

        tha=(sqr(b)+sqr(c)-sqr(a))/(2*b*c);

        thb=(sqr(a)+sqr(c)-sqr(b))/(2*a*c);

        thc=(sqr(b)+sqr(a)-sqr(c))/(2*b*a);

        tha=acos(tha);

        thb=acos(thb);

        thc=acos(thc);

        double s2=tha/2*sqr(r3)+thb/2*sqr(r1)+thc/2*sqr(r2);

        printf("Case %d: %.2lf %.2lf\n",i++,s1,s2);

    }

    return 0;

}


 

 

你可能感兴趣的:(uva)