Description
In a given cartesian plane, there are N points. We need to find the Number of Pairs of points(A,B) such that
Point A and Point B do not coincide.
Manhattan Distance and the Euclidean Distance between the points should be equal.
Note : Pair of 2 points(A,B) is considered same as Pair of 2 points(B,A).
Manhattan Distance = |x2-x1|+|y2-y1|
Euclidean Distance = ((x2-x1)^2 + (y2-y1)2)0.5 where points are (x1,y1) and (x2,y2).
Constraints:1<=T <= 50, 1<=N <= 2*10 ^ 5, 0<=(|Xi|, |Yi|) <= 10^9
Input
First Line Consist of T - number of test cases. For each Test case:First Line consist of N , Number of points. Next line contains N pairs contains two integers Xi and Yi,i.e, X coordinate and the Y coordinate of a Point
Output
Print the number of pairs as asked above.
Sample Input 1
1
2
1 1
7 5
Sample Output 1
0
注:因为题目中说明A、B点不重合,所以不用考虑横、纵坐标相等的情况了,之前测试用例有问题,导致没法通过.
import collections
# 坐标集合、坐标个数
def solution(input_l, number):
res = 0
x_l = []
y_l = []
for p in range(number):
x_l.append(input_l[p][0])
y_l.append(input_l[p][1])
# 统计横、纵坐标的值和出现的次数
x = collections.Counter(x_l)
y = collections.Counter(y_l)
for m in x:
res += (x[m] * (x[m] - 1)) // 2
for n in y:
res += (y[n] * (y[n] - 1)) // 2
return res
if __name__ == '__main__':
n = int(input())
for i in range(n):
input_l = []
number = int(input())
for j in range(number):
l = list(map(int, input().strip().split()))
input_l.append(l)
result = solution(input_l, number)
print(result)