Problem Statement
There is a 2-D plane and there are N points. i-th point is located at (X[i], Y[i]).
You are going to choose 3 distinct points from them. Then, we calculate:
longest = the longest distance between two of the three points shortest = the shortest distance between two of the three pointsYou want to pick the three points that minimize the value, longest/shortest. Given int[] X and int[] Y, return this smallest value.
Definition
- Class:
- MakingRightyTriangle
- Method:
- best
- Parameters:
- int[], int[]
- Returns:
- double
- Method signature:
- double best(int[] X, int[] Y)
- (be sure your method is public)
Constraints
- The number of elements in X will be between 3 and 200, inclusive.
- The number of elements in Y will be between 3 and 200, inclusive.
- X and Y will have the same number of elements.
- Each element in X will be between -1,000 and 1,000 inclusive.
- Each element in Y will be between -1,000 and 1,000 inclusive.
- (X[i], Y[i]) will be pairwise distinct.
Examples
{0,0,1,1}{0,1,0,1}Returns: 1.4142135623730951
{0,0,0}{0,1,2}Returns: 2.0
It is possible to choose 3 points that are in a straight line.{114,514,-810,893,364,334}{-134,22,482,103,276,-912}Returns: 1.433199134719805
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}{3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4}Returns: 1.0749676997731399