TRICENTR - Triangle From Centroid

Given the length of side a of a triangle and the distances from the centroid (the point of concurrence of the medians - red in the picture) to all sides: a, b and c, calculate this triangle's area and the distance (blue line) from the orthocenter (the point of concurrence of the heights - green in the picture) to the centroid.

Input

In the first line integer n - the number of test cases (equal to about 1000). The next n lines - 4 floating point values: the length of side a, and distances from the centroid to sides a, b and c.

Output

n lines consisting of 2 floating point values with 3 digits after the decimal point: the area of the triangle and the distance from the orthocenter to centroid.

Example

Input:
2
3.0 0.8660254038 0.8660254038 0.8660254038
657.8256599140 151.6154399062 213.5392629932 139.4878846649

Output:
3.897 0.000
149604.790 150.275

Added by:Patryk Pomykalski
Date:2004-05-22
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS PERL6 VB.NET

hide comments
2015-10-24 15:20:53
The solutions of this problem are not right . The person who framed the problem seems to have rounded off values somewhere in the intermediary steps . My answers for the sample input are : 149604.781 150.274
and 3.897 0.000 .
2015-09-11 18:37:28 puntu
though i am getting the correct answer in my ide but i think the rounding off trchnique followed by them and my ide i different, so they r giving me W/A.
2015-09-11 18:36:21 puntu
apply that the distance from the centroid to the orthocentre is twice that of the distance from the centroid to the circumcentre. so challenge is to calculate the distance from the centroid to the circumcentre.
2015-09-02 11:20:04
Aren't the conditions
b=a*ga/gb;
c=a*ga/gc;
true when the median and the altitude is same....because centroid divides the median in the ratio 2:1.
The conditions are true for equilateral and isosceles triangle but what about the other triangles?

Last edit: 2015-09-02 11:20:38
2015-07-02 13:42:48 Anushka
Is there any straight formula to calculate distance between centroid and orthocentre?? I googled up a formula but it is giving wrong answer
2015-05-28 21:30:39 ASHUTOSH DWIVEDI
@ Harunur Rashid As the perpendicular distance is given from centroid
two smaller triangles forming are similar and hence
b=a*ga/gb;
c=a*ga/gc;
2014-11-11 01:24:56 Ruffneck
maths maths maths
2014-08-18 22:36:53 Harunur Rashid
b=a*ga/gb;
c=a*ga/gc;
how is it possible.Explain please
2013-12-31 18:35:09 mayank
purely formula based! nothing sepcial required! and @liz can you tell how do you plan to do this question without the measure of length side 'a' ? My mail id is mayank25080562@gmail.com
2013-11-10 10:20:35 liz
Actually the length of side a is not necessary. One can solve the problem using only distances from the centroid to the sides.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.