Question:
Solution:
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 realnumbers, 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.
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 realnumbers, 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(){
......
.....
.....
if(a==0||b==0||c==0)
printf("-1.000\n");
else if(a+b+c-max<=max)
printf("-1.000\n");
printf("-1.000\n");
else if(a+b+c-max<=max)
printf("-1.000\n");
else{
.......
........
result=(2*(a*a*b*b+b*b*c*c+c*c*a*a))-((pow(a,4)+pow(b,4)+pow(c,4)));
area=((sqrt(result))/3);
area=((sqrt(result))/3);
.......
........
}
}
No comments:
Post a Comment