`
scott________
  • 浏览: 20862 次
  • 性别: Icon_minigender_1
  • 来自: 哈尔滨
最近访客 更多访客>>
社区版块
存档分类
最新评论

pc 111303 uva 10195 The Knights Of The Round Table

阅读更多
题目描述:http://www.programming-challenges.com/pg.php?page=downloadproblem&probid=111303&format=html

题目大意:给定三角形三边长,求内接圆半径。

//解该题需要一些三角形知识:
//1. p 为三角形周长一半,即 p = (a+b+c)/2.0
//   三角形面积 S = sqrt(p*(p-a)*(p-b)*(p-c))(海伦公式)
//2. 内接圆半径 r = S/p
// 另外该题还有一个很无聊的陷阱
// 当有一条边为 0 时,输出为:0.000,需要特殊处理

#include <cstdio>
#include <cmath>

int main() {
	double a, b, c, p;
	while(scanf("%lf %lf %lf", &a, &b, &c) != EOF) {
		if(a == 0 || b == 0 || c == 0)
			printf("The radius of the round table is: %.3lf\n", 0);
		else {
			p = (a + b + c) / 2.0;
			printf("The radius of the round table is: %.3lf\n", 
				   sqrt((p - a) * (p - b) * (p - c) / p));
	}
	}
	return 0;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics