Pagini recente » Cod sursa (job #1231404) | Cod sursa (job #706266) | Cod sursa (job #2309522) | Cod sursa (job #2876777) | Cod sursa (job #3165710)
#include <bits/stdc++.h>
using namespace std;
double calcDist(pair<double, double> x, pair<double, double> y) {
return sqrt((x.first - y.first) * (x.first - y.first) + (x.second - y.second) * (x.second - y.second));
}
double round3(double x) {
x = x * 1000;
x = (int) x;
return x / 1000.0;
}
struct pair_hash {
inline size_t operator()(const std::pair<double, double> & v) const {
return v.first * 997 + v.second;
}
};
int n, ans;
vector<pair<double, double>> v;
unordered_map<pair<double, double>, bool, pair_hash> m;
int main() {
ifstream cin("triang.in");
ofstream cout("triang.out");
cin >> n;
for (int i = 1; i <= n; ++i) {
double x, y;
cin >> x >> y;
x = round3(x);
y = round3(y);
v.push_back({x, y});
m[{x, y}] = true;
}
sort(v.begin(), v.end());
for (int i = 0; i < v.size(); ++i) {
for (int j = i + 1; j < v.size(); ++j) {
double b = calcDist(v[i], v[j]) * sqrt(3) / 2;
pair<double, double> start = {(v[i].first + v[j].first) / 2, (v[i].second + v[j].second) / 2};
double degree, x, y;
if (abs(v[i].first - v[j].first) == 0) {
degree = 3.14159 / 2;
x = -b;
y = 0;
} else {
degree = round3(tan(abs(v[i].second - v[j].second) / abs(v[i].first - v[j].first)));
x = -b * sin(degree);
y = -b * cos(degree);
}
pair<double, double> top;
if (v[i].second > v[j].second) {
top = {round3(start.first + abs(x)), round3(start.second + abs(y))};
} else {
top = {round3(start.first - abs(x)), round3(start.second + abs(y))};
}
if (m.find(top) != m.end()) {
++ans;
}
if (m.find({-top.first, - top.second}) != m.end()) {
++ans;
}
}
}
cout << ans;
}