就可求得半徑r。
內接圓半徑 = 2 * S / (a + b + c)
p = (a + b + c) / 2代入,S用海龍代入。
化簡可得
√[(p - a) * (p - b) * (p - c) / p]。
唯一要注意的是,input可能為0,
這時候不構成三角形,因此也沒有所謂的內接圓半徑。
(WTF)
/* ACM 10195 The Knights Of The Round Table
* mythnc
* 2012/01/02 09:56:51
* run time: 0.008
*/
#include <stdio.h>
#include <math.h>
double radius(double, double, double);
int main(void)
{
double a, b, c;
while (scanf("%lf %lf %lf", &a, &b, &c) == 3)
printf("The radius of the round table is: %.3f\n", radius(a, b, c));
return 0;
}
double radius(double a, double b, double c)
{
double p;
if (a == 0.0 || b == 0.0 || c == 0.0)
return 0.0;
p = (a + b + c) / 2.0;
return sqrt((p - a) * (p - b) * (p - c) / p);
}
沒有留言:
張貼留言