UVa 10522 - Height to Area

题目:一直三角形三条高,求面积。

分析:计算几何。设面积为S,则三角形三边分别为:S/h1,S/h2,S/h3;利用海伦公式可以确定三边和S的关系

            推导得:S = 1/sqrt((1/h1+1/h2+1.h3)*(1/h1+1/h2-1/h3)*(1/h1+1/h3-1/h2)*(1/h2+1/h3-1/h1));

注意:如果返回SubmissionErr,就认为是 In queue 

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

int main()
{
	int    n,count;
	double a,b,c,s;
	while ( ~scanf("%d",&n) ) {
		count = 0;
		do {
			scanf("%lf%lf%lf",&a,&b,&c);
			a = 1.0/a;b = 1.0/b;c = 1.0/c;
			s = (a+b+c)*(a+b-c)*(a+c-b)*(b+c-a);
			if ( s < 0 ) 
				printf("These are invalid inputs!\n");
			else printf("%.3lf\n",1.0/sqrt(s));
		}while ( count < n );
	}
	return 0;
}

你可能感兴趣的:(UVa 10522 - Height to Area)