Tuesday, November 30, 2010

UVA Problem#10347


It's a bit tricky to derive the formula for this problem. Basically, you can prove that the area of the triangle formed by the medians is 3/4 of the area of the original triangle. Then, you can use Heron's formula to get the area of the median triangle, and multiply by 4/3. So in all:

A = (4/3) * sqrt(s(s-m1)(s-m2)(s-m3))

Where m1, m2, and m3 are the median lengths, and s is the semiperimeter of the median triangle:

s = (m1 + m2 + m3) / 2

There are some tricky things to watch out for:

1) The inputs can be real
numbers, they need not be integers

2) Output -1 as -1.000

3) The problem is unfortunately worded when it says "The areas should be rounded up". They really mean normal rounding (i.e. round-half-up)

4) Output -1 if a median length is less than or equal to 0, if the area is less than or equal to 0, or if you'd end up with a negative square root.

int main(){

        else if(a+b+c-max<=max)

No comments:

Post a Comment