1. You do not need to fix the output up to 6 decimal places. it has already been taken care of. Just return the output in the data type mentioned in the function.
2. Lines ‘AB’ and ‘PQ’ are two different lines.
The first line of input contains an integer ’T’ which denotes the number of test cases or queries to be run. Then the test cases follow.
The first line of each test case contains 8 single space-separated integers ‘AX1’,’ AY1’, ’BX2’, ’BY2’, ’PX1’, ’PY1’, ’QX2’, ’QY2’ where ’AX1’ represents the ‘X’ coordinate of the point ‘A’ and ‘AY1’ represents the ‘Y’ coordinate of the point ‘A’ and so on.
For each test case, print the ‘X’ and ‘Y’ coordinates of the point of intersection of the two lines ‘AB’ and ‘PQ’ up to 6 decimal places.
Print the output of each test case in a separate line.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= ‘T’ <= 10^2
1 <= ‘N’ <= 5*10^3
1 <= ‘AX1’, ’AY1’, ’BX2’, ’BY2’, ’PX1’, ’PY1’, ’QX2’, ’QY2’ <= 10^5
Where ‘T’ denotes the total number of test cases, ‘N’ represents the number of boxes, ‘AX1’, ’AY1’, ’BX2’, ’BY2’, ’PX1’, ’PY1’, ’QX2’, ’QY2’ represents the the ‘X’ coordinate of the point ‘A’ and ‘AY1’ represents the ‘Y’ coordinate of the point ‘A’ and so on.
Time Limit: 1 sec
The idea behind this approach is to derive the equation of both of the lines ‘AB’ and ‘PQ’ and check if the Slope of these two lines is equal or not. Following are the two cases:
For a better understanding of this approach, Assume that we have two points which are A(a1, b1) and B(a2, b2). Now, we have to find the equation of line formed by points ‘A’ and ‘B’.
Now we have to solve these 2 equations to get the point of intersection of these two lines. To solve this problem, we can multiply equation 1 by b2 and equation 2 by b1,this gives us the following result:
Here is the complete algorithm:
Merge Two Sorted Arrays Without Extra Space
Ninja And The Strictly Increasing Array
Maximum GCD
Prime?
Co-Prime