17.距离问题

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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值