Pagini recente » Cod sursa (job #3337559) | Cod sursa (job #3307731) | Cod sursa (job #266008) | Cod sursa (job #455354) | Cod sursa (job #3331583)
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
ifstream fin("patrate3.in");
ofstream fout("patrate3.out");
const int NMAX = 1000;
const ld INF = 1e18;
const ld EPS = 1e-8;
int n;
ll answer;
int x[NMAX + 1], y[NMAX + 1];
vector<pair<ld, ll>> v;
ld get_slope(int x1, int y1, int x2, int y2) {
if(x2 - x1 == 0) {
return INF;
}
return (ld)(y2 - y1) / (ld)(x2 - x1);
}
ll get_distance(int x1, int y1, int x2, int y2) {
return (ll)(x2 - x1) * (x2 - x1) + (ll)(y2 - y1) * (y2 - y1);
}
bool is_equal(pair<ld, ll> a, pair<ld, ll> b) {
if(abs(a.first - b.first) <= EPS && a.second == b.second) {
return true;
}
return false;
}
int main()
{
fin >> n;
for(int i = 1; i <= n; i++) {
ld xx, yy;
fin >> xx >> yy;
x[i] = round(xx * 10000);
y[i] = round(yy * 10000);
}
for(int i = 1; i <= n; i++) {
for(int j = i + 1; j <= n; j++) {
ld slope = get_slope(x[i], y[i], x[j], y[j]);
assert(slope <= INF);
ll dist = get_distance(x[i], y[i], x[j], y[j]);
v.emplace_back(slope, dist);
}
}
sort(v.begin(), v.end());
int l = 1;
for(int i = 1; i < (int) v.size(); i++) {
if(is_equal(v[i], v[i - 1])) {
l++;
}
else {
answer += (ll) l * (l - 1) / 2;
l = 1;
}
}
answer += (ll) l * (l - 1) / 2;
fout << answer / 2 << '\n';
return 0;
}