
1. The distance between two points (X1, Y1) and (X2, Y2) is calculated as [ (X1 - X2) ^ 2 + (Y1 - Y2) ^ 2 ] i.e without a square root.
2. The order of tuples matters.
Suppose the given 'DISTANCE' array/list is [ [ 0, 0 ], [ 1, 0 ], [ 2, 0 ] ]. We return ‘2’as the answer as only two affair points are there as follows:
[ [ 1, 0 ], [ 0, 0 ], [ 2, 0 ] as ( ( 0 - 1) * ( 0 - 1 ) + (0 - 0 ) * ( 0 - 0 ) = ( 2 - 1 ) * ( 2 - 1 ) + ( 0 - 0 ) * ( 0 - 0 ) = 1
Distance of [1, 0] is same for [0, 0] and [2, 0].
[ [ 1, 0 ], [ 2, 0 ], [ 0, 0 ] ] as ( ( 2 - 1 ) * ( 2 - 1 ) + ( 0 - 0 ) * ( 0 - 0 ) = ( 0- 1 ) * ( 0 - 1 ) + ( 0 - 0 ) * ( 0 - 0 )
Distance of [1, 0] is same for [2, 0] and [0, 0].
The first line of input contains the ‘T’ number of test cases.
The first line of each test case contains an integer ‘N’ denoting the number of points in the ‘DISTANCE’ list/array. Then, ‘N’ lines follow.
Each line contains two space-separated integers denoting the points ‘Xi, Yi’.
For each test case, print a single line containing a single integer denoting the total number of possible affair points.
The output of each test case will be printed in a separate line.
You are not required to print anything explicitly. It has already been taken care of. Just implement the function.
1 <= ‘T’ <= 50
1 <= ‘N’ <= 100
-10000 <= ‘DISTANCE[i][0]’, 'DISTANCE[i][1] <= 10000
Where ‘T’ represents the number of test cases, ‘N’ represents the size of the ‘DISTANCE’ array/list, and 'DISTANCE[i][0]' represents the point 'Xi' and 'DISTANCE[i][1]' represents the point 'Yi'.
Time Limit: 1 sec.
The idea here is to use the brute force approach and check for each and every possible pair. If there is any pair of points satisfying the given condition of being an affair point, we increase the count by ‘1’.
The idea here is to store the distances in the map. Now if the same distance comes, we can count how many times the same distance has already occurred and we can increase the count by that number of occurrences without the need for checking with each pair. Thus, the time complexity can be reduced.