MaxTriangle
SRM 449 · 2009-09-23 · by dzhulgakov
SRM 449 · 2009-09-23 · by dzhulgakov · Geometry, Simple Search, Iteration
Problem Statement
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.
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).
3)
194 881 Returns: 202.5
4)
1000000000 1000000000 Returns: 5.0E8
Submissions are judged against all 97 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class MaxTriangle with a public method double calculateArea(int A, int B) · 97 test cases · 2 s / 256 MB per case