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;
}


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值