2012-04-20 16:28:02Morris

[UVA][Math] 10347 - Medians

Problem C
Medians

Input: standard input
Output: standard output
Time Limit: 1 second
Memory Limit: 32 MB

Given the length of three medians of a triangle you will have to find out the area of the triangle. Unless you are weak in geometry you should know that median of a triangle is formed by connecting any vertex of a triangle and the mid-point of its opposite edge. So a triangle has three medians.

Input

The input file contains 1000 lines of input. Each line contains three numbers which denote the length of the medians of a triangle. All the values in the input will be less than 100. Input is terminated by end of file.

Output

For each line of input you should produce one line of output. This line should contain the area of the triangle for the corresponding input. If it is not possible to form a triangle with the given medians, the area of the triangle should be set as -1. The areas should be rounded up to three digits after the decimal point.

Sample Input

3 3 3

3 3 3 

Sample Output

5.196

5.196



三中線交點是重心,用海龍公式求面積


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

int main() {
    double a, b, c;
    while(scanf("%lf %lf %lf", &a, &b, &c) == 3) {
        if(a+b <= c || b+c <= a || c+a <= b) {
            puts("-1.000");
            continue;
        }
        a = a*(2/3.0);
        b = b*(2/3.0);
        c = c*(2/3.0);
        double s = (a+b+c)/2.0;
        printf("%.3lf\n", 3*sqrt(s*(s-a)*(s-b)*(s-c)));
    }
    return 0;
}