# 447.Number of Boomerangs

**447.Number of Boomerangs**

难度:Easy

> 给定平面上 n 对不同的点，“回旋镖” 是由点表示的元组 (i, j, k) ，其中 i 和 j 之间的距离和 i 和 k 之间的距离相等（需要考虑元组的顺序）。

找到所有回旋镖的数量。你可以假设 n 最大为 500，所有点的坐标在闭区间 \[-10000, 10000] 中。

```
示例:

输入:
[[0,0],[1,0],[2,0]]

输出:
2

解释:
两个回旋镖为 [[1,0],[0,0],[2,0]] 和 [[1,0],[2,0],[0,0]]
```

建立一个表示距离关系的矩阵，然后统计每行相同距离的点。

```
class Solution {
public:
    int numberOfBoomerangs(vector<vector<int>>& points) {
        int N=points.size();
        vector<vector<int>> distance(N, vector<int>(N,0));
        for(int i=0;i<N;i++)
            for(int j=i+1;j<N;j++)
            {
                distance[j][i]=distance[i][j]=pow((points[i][0]-points[j][0]),2)+pow((points[i][1]-points[j][1]),2);
                //cout<< distance[i][j]<<endl;
            }
        int sum=0;
        for(int i=0;i<N;i++)
        {
            unordered_map<int,int>tmp;
            for(int j=0;j<N;j++)
            {
                if(tmp.count(distance[i][j])) 
                   tmp[distance[i][j]]++ ;
                else 
                   tmp[distance[i][j]]=1;
            }
            for(auto iter=tmp.begin();iter!= tmp.end();iter++)
                   if(iter->second >1)
                   sum+=(iter->second)*(iter->second -1);
        }
        return sum;
    }
};
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dfine.gitbook.io/leetcode/447.number_of_boomerangs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
