题目来源:
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=439
分析:
三角形面积:
area = sqrt(p (p - a) (p -b)(p -c))
p = (a + b +c) / 2;
三角形内接圆 半径 rin = 2 * area / l l 为周长
三角形外接圆 半径 rout = abc / (4*area) ;
代码如下:
double add(double a, double b){ return (fabs(a+b) < EPS * (fabs(a) + fabs(b))) ? 0 : (a + b) ; } struct Point{ double x, y ,z ; Point(){} Point(double x, double y, double z):x(x),y(y),z(z){} } ; double dist(Point a, Point b){ return sqrt( add( add( (a.x - b.x)*(a.x - b.x) ,(a.y - b.y)*(a.y - b.y) ) ,(a.z - b.z)*(a.z - b.z) ) ) ; } Point a, b , c; int main() { while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf",&a.x ,&a.y ,&a.z , &b.x , &b.y ,&b.z ,&c.x , &c.y ,&c.z ) != EOF){ double aa = dist(b,c) ; double bb = dist(a,c) ; double cc = dist(a,b) ; double p = (aa +bb +cc) * 0.5 ; double area = sqrt(p*(p - aa)*(p - bb)*(p - cc)) ; double rout = aa * bb * cc / 4 / area ; double rin = area / p ; printf("%.3lf\n" , rin * rin / rout / rout) ; } }