Reputation: 331
I have come across a problem. The problem statement is
A team of 3 people, is going to participate in a competition. According to the regulations of this competition, every team is given a single computer, which is located on a triangular table, and three chairs.
Team thinks that the most convenient location of participants is the one where each of the three participants sits at his/her own side of the triangular table, and, what’s important, exactly at the middle of this side. Of course, chairs should be put the same way.
It is important that, during the competition, the participants sit not very far one from another. The Dream Team’s captain thinks that a proper estimation of this factor is an average distance between all the pairs of these participants.
In the case of this competition, one have to compute an average distance between the middle points of the sides of a triangular table. Write a program which computes exactly this. Note that the distance is Euclidean – that is, the distance between (x1,y1) and (x2,y2) is sqrt((x_1 - x_2)^2 + (y_1 - y_2)^2).
Input
The input file contains three positive integer numbers not exceeding 100 – the lengths of sides of the table. It is guaranteed that such a table will have a non-zero area.
Output
Output the average distance between the middle points of the sides of the table, which was described in the input.
Examples
Input Output
3 4 5 2.00000000
5 5 7 2.83333333
I thought of one way to solve this
1. Assume origin as 1 point.
2. If one of the length is 3, assume the point as (3,0).
3. Now, I struck at finding 3rd coordinate
Is my approach, Ok?
Please, give me an algorithm to solve this.
Thank you
Upvotes: 1
Views: 988
Reputation: 80197
Note that segment, connecting middle of edge A and middle of edge B, is half of edge C and the same is true for other sides.
So solution is very simple - average distance for triangle with side lengths A,B,C is
M = (A/2 + B/2 + C/2) / 3 =
(A + B + C ) / 6
Upvotes: 9