天天看點

Ex-circles - UVa 11731 幾何

題意:給你三角形的三條邊,求圖中DEF的面積和陰影部分的面積。

思路:這是一個旁切圓的問題,三角形關于頂點A、B、C的旁切圓的半徑分别是

Ex-circles - UVa 11731 幾何

Ex-circles - UVa 11731 幾何

Ex-circles - UVa 11731 幾何

,其中

Ex-circles - UVa 11731 幾何

表示三角形面積,a、b、c分别是A、B、C的對邊。

另外補充知識點:

若頂點的坐标分别為

Ex-circles - UVa 11731 幾何

Ex-circles - UVa 11731 幾何

Ex-circles - UVa 11731 幾何

,則三個旁心的座标為:

Ex-circles - UVa 11731 幾何

AC代碼如下:

#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
double angle(double a,double b,double c)
{
    return acos((a*a+b*b-c*c)/(2*a*b));
}
double area(double a,double b,double c)
{
    double p=(a+b+c)/2;
    return sqrt(p*(p-a)*(p-b)*(p-c));
}
double eps=1e-8;
int main()
{
    int t=0,i,j,k;
    double a,b,c,A,B,C,S,ra,rb,rc,ans1,ans2;
    while(~scanf("%lf%lf%lf",&a,&b,&c) && a+b+c>eps)
    {
        S=area(a,b,c);
        A=angle(b,c,a);
        B=angle(a,c,b);
        C=angle(a,b,c);
        ra=2*S/(b+c-a);
        rb=2*S/(a+c-b);
        rc=2*S/(a+b-c);
        ans1=S+(a*ra+b*rb+c*rc)/2;
        ans2=(M_PI/2-A/2)*ra*ra+(M_PI/2-B/2)*rb*rb+(M_PI/2-C/2)*rc*rc;
        ans2/=2;
        printf("Case %d: %.2f %.2f\n",++t,ans1,ans2);
    }
}