UVa 11731 - Ex-circles

链接

传送门

题意

给出一个三角形和它的三个旁切圆,求指定部分的面积。具体见原题。

思路

利用旁切圆半径公式即可。

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

double Area(double a, double b, double c) {
double p = (a + b + c) / 2;
return sqrt(p * (p - a) * (p - b) * (p - c));
}

double Ang(double a, double b, double c) {
return acos((c * c - a * a - b * b) / (2 * a * b));
}

int main() {
int a, b, c, t = 0;
while (~scanf("%d%d%d", &a, &b, &c) && (a || b || c)) {
double S = Area(a, b, c);
double ra = 2 * S / (-a + b + c);
double rb = 2 * S / (a - b + c);
double rc = 2 * S / (a + b - c);
double A = Ang(b, c, a);
double B = Ang(a, c, b);
double C = Ang(a, b, c);
double ans1 = S + (a * ra + b * rb + c * rc) / 2;
double ans2 = A * ra * ra + B * rb * rb + C * rc * rc;
printf("Case %d: %.2f %.2f\n", ++t, ans1, ans2 / 4);
}
return 0;
}