TopCoder problem "MaxTriangle" used in SRM 449 (Division I Level One)



Problem Statement

    A triangle with positive area has been positioned on the plane in such a way that all of its vertices are located at integer coordinates. The lengths of two sides of this triangle are equal to sqrt(A) and sqrt(B), where sqrt(X) denotes the square root of X. Return the maximum area this triangle can have. If there is no such triangle, return -1 instead.
 

Definition

    
Class:MaxTriangle
Method:calculateArea
Parameters:int, int
Returns:double
Method signature:double calculateArea(int A, int B)
(be sure your method is public)
    
 

Notes

-The returned value must be accurate to within a relative or absolute value of 1E-9.
 

Constraints

-A and B will each be between 1 and 2000000000, inclusive.
 

Examples

0)
    
1
1
Returns: 0.5
1)
    
3
7
Returns: -1.0
2)
    
41
85
Returns: 29.5
One possible triangle has vertices at (-1, 1), (6, -5) and (10, 0).

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=10548

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13903&pm=10548

Writer:

dzhulgakov

Testers:

PabloGilberto , ivan_metelsky , zhuzeyuan

Problem categories:

Geometry, Simple Search, Iteration