The Knights Of The Round Table

The Knights Of The Round Table

时间: 1ms        内存:64M

描述:

King Arthur is planning to build the round table in a room which has a triangular window in the ceiling. He wants the sun to shine on his round table. In particular, he wants the table to be totally in the sunlight when the sun is directly overhead at noon.

Thus the table must be built in a particular triangular region of the room. Of course, the king wants to build the largest possible table under the circumstances.

As Merlin is out to lunch, write a program which finds the radius of the largest circular table that fits in the sunlit area.

输入:

There will be an arbitrary number of test cases, each represented by three real numbers (a, b, and c), which stand for the side lengths of the triangular region. No side length will be greater than 1,000,000, and you may assume that max(a, b, c)<=(a + b + c)/2. You must read until you reach the end of the file.

输出:

For each room configuration read, you must print the following line:

The radius of the round table is: r

where r is the radius of the largest round table that fits in the sunlit area, rounded to three decimal digits.

示例输入:

12.0 12.0 8.0

示例输出:

The radius of the round table is: 2.828

提示:

参考答案(内存最优[760]):

#include <stdio.h>
#include <math.h>
int main(){
	double a,b,c,p,s,r;
	while(scanf("%lf%lf%lf",&a,&b,&c)==3){
		if(a==0.0 || b==0.0 || c==0.0)
			r=0.0;
		else{
			p=(a+b+c)/2;
			s=sqrt(p*(p-a)*(p-b)*(p-c));
			r=2*s/(a+b+c);
		}
		printf("The radius of the round table is: %.3lf\n",r);
	}
	return 0;
}

参考答案(时间最优[0]):

#include <stdio.h>
#include <math.h>
int main(){
	double a,b,c,p,s,r;
	while(scanf("%lf%lf%lf",&a,&b,&c)==3){
		if(a==0.0 || b==0.0 || c==0.0)
			r=0.0;
		else{
			p=(a+b+c)/2;
			s=sqrt(p*(p-a)*(p-b)*(p-c));
			r=2*s/(a+b+c);
		}
		printf("The radius of the round table is: %.3lf\n",r);
	}
	return 0;
}

题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。

点赞