UVa 10195 - The Knights Of The Round Table

来源:互联网 发布:生活品质 知乎 编辑:程序博客网 时间:2024/04/28 17:47

题目:圆桌骑士0 0?给出三角形三边长度,求内切圆半径。

分析:简单题、计算几何。利用三角形面积联立等式。S = (a+b+c)*r = 0.5*sqrt(p*(p-a)*(p-b)*(p-c))(海伦公式、p=0.5*(a+b+c))。

注意:l1+l2+l3可能为0。

#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){double l1,l2,l3;while ( scanf("%lf%lf%lf",&l1,&l2,&l3) != EOF ) {double p = (l1+l2+l3)*0.5;double s = sqrt(p*(p-l1)*(p-l2)*(p-l3));double r = (l1+l2+l3)?2.0*s/(l1+l2+l3):0.0;printf("The radius of the round table is: %.3lf\n",r);}return 0;}

原创粉丝点击