
You have to use Euclidean distance i.e., sqrt((y2 - y1)^2 + (x2 - x1)^2)
You have to return the time with the precision of up to 6 decimal places.
You are given ‘locations’ = [[0, 2], [0, 0], [2, 0]], and ‘speed’ = 2, then the maximum time will be between points [0, 2], [2, 0] which is 1.41421356237. Hence the answer rounded up to 6 decimal places is 1.414214.
The first line of input contains the integer ‘T’ representing the number of test cases.
The first line of each test case contains two space-separated integers, 'N' and 'speed', representing the number of locations and speed, respectively.
The next ‘N’ lines contain two space-separated integers, ‘x’ and ‘y’, representing the point in coordinate space as a location.
For each test case, print a positive real number, up to 6 decimal places, representing the maximum time it will take traveling between any two locations.
Print a separate line for each test case.
1 <= T <= 10
1 <= N <= 10^5
1 <= speed <= 10^5
2 <= x, y <= 10^5
Time Limit: 1 sec
You do not need to print anything. It has already been taken care of. Just implement the function.
In this approach, we will sort all the points by their X Coordinates. Then we will iterate through every possible coordinate combination and find the maximum distance among all points.
Then divide the maximum distance by speed to find the maximum time.
Algorithm:
This approach will use the convex hull of the given points, as the two points with the maximum distance will be present on the convex hull. After getting the maximum distance, we can find the maximum time by dividing it by speed.
For this algorithm, we also need to know:
Then we will apply the rotating calliper algorithm to find the two points.
Step 1: Get the Convex Hull in a clockwise or counterclockwise manner.
Step 2: Finding Lower and Upper Section of Hull
There are N points of the convex hull which are P1, P2, …. PN, in a counterclockwise direction.
Step 3: Finding the maximum distance points
We create a Point class with x and y attributes denoting (x, y) coordinate of the point.
We create getSquaredDistance(pointA, pointB), function, which will return squared distance between pointA, pointB.
We create a getCrossProduct(a, b, c) which will return the value of the cross product between the vectors formed by points ab and ac, i.e., it will return |ab X ac|
We create a function getConvexHull(points), which will return the convex hull of the given Point array, points, it will return convex hull in a counterclockwise direction.
Algorithm:
Construct The Parameter
Construct The Parameter
Construct The Parameter
Construct The Parameter
Construct The Parameter
Construct The Parameter
Construct The Parameter
Construct The Parameter
Construct The Parameter
Construct The Parameter
Construct The Parameter
Construct The Parameter
Construct The Parameter
Points Visible
Points Visible
Points Visible
Circle Intersection
Circle Intersection
Circle Intersection
Circle Intersection
City Lights
Angler's Race