-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path447.cpp
More file actions
executable file
·33 lines (31 loc) · 1.37 KB
/
447.cpp
File metadata and controls
executable file
·33 lines (31 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Solution {
public:
int numberOfBoomerangs(vector<vector<int>>& points) {
vector<vector<double> > distance(points.size(), vector<double>(points.size(), 0));
unordered_map<int,unordered_map<double, int>> i2distance2j;
for (int i = 0; i < points.size(); i++)
for (int j = i + 1; j < points.size(); j++){
if (i != j){
distance[i][j] = (double)sqrt((points[i][0] - points[j][0])*(points[i][0] - points[j][0]) + (points[i][1] - points[j][1])*(points[i][1] - points[j][1]));
if (i2distance2j[i].count(distance[i][j])){
i2distance2j[i][distance[i][j]] += 1;
}else{
i2distance2j[i][distance[i][j]] = 1;
}
distance[j][i] = distance[i][j];
if (i2distance2j[j].count(distance[j][i])){
i2distance2j[j][distance[j][i]] += 1;
}else{
i2distance2j[j][distance[j][i]] = 1;
}
}
}
int res = 0;
for (int i = 0; i < points.size(); i ++)
for (int j = 0; j < points.size(); j++)
if (i != j){
res += (i2distance2j[i][distance[i][j]] - 1);
}
return res;
}
};