蓝桥杯B组C++ E
作者:
每天吃不饱
,
2023-06-10 14:05:25
,
所有人可见
,
阅读 216
#include <bits/stdc++.h>
using i64 = long long;
i64 distanceSquared(i64 x1, i64 y1, i64 x2, i64 y2) {
i64 dx = x2 - x1;
i64 dy = y2 - y1;
return dx * dx + dy * dy;
}
i64 countIsoscelesTriangles(const std::vector<std::pair<i64, i64>> &points) {
i64 count = 0;
std::unordered_map<i64, i64> distanceCount;
for (size_t i = 0; i < points.size(); i++) {
for (size_t j = i + 1; j < points.size(); j++) {
i64 dist = distanceSquared(points[i].first, points[i].second, points[j].first, points[j].second);
distanceCount[dist]++;
}
}
for (const auto &pair: distanceCount) {
i64 freq = pair.second;
count += freq * (freq - 1) / 2;
}
return count;
}
void solve() {
i64 n;
std::cin >> n;
std::vector<std::pair<i64, i64>> points;
for (i64 i = 0; i < n; i++) {
i64 x, y;
std::cin >> x >> y;
points.push_back({x, y});
}
i64 result = countIsoscelesTriangles(points);
std::cout << result << std::endl;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
solve();
return 0;
}
代码无法处理一些特殊情况,欢迎评论区击剑🤺