Pagini recente » Cod sursa (job #229716) | Cod sursa (job #2087239) | Cod sursa (job #2308908) | Cod sursa (job #374094) | Cod sursa (job #3331601)
#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-6;
struct Simon {
ld slope;
ll dist;
int mid_x2, mid_y2;
bool operator < (const Simon& other) const {
if(slope - other.slope < -EPS) {
return true;
}
else if(abs(slope - other.slope <= EPS) && dist < other.dist) {
return true;
}
if(abs(slope - other.slope <= EPS) && dist == other.dist && mid_x2 < other.mid_x2) {
return true;
}
if(abs(slope - other.slope <= EPS) && dist == other.dist && mid_x2 == other.mid_x2 && mid_y2 < other.mid_y2) {
return true;
}
return false;
}
bool operator == (const Simon& other) const {
return !(*this < other) && !(other < *this);
}
};
int n, ind, answer;
int x[NMAX + 1], y[NMAX + 1];
Simon v[NMAX * NMAX + 1];
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]);
int mid_x2 = (x[i] + x[j]);
int mid_y2 = (y[i] + y[j]);
v[++ind] = {slope, dist, mid_x2, mid_y2};
}
}
sort(v + 1, v + ind + 1);
// for(auto x : v) {
// fout << x.slope << ' ' << x.dist << ' ' << x.mid_x2 << ' ' << x.mid_y2 << '\n';
// }
// fout << '\n';
// 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]);
// ll dist = get_distance(x[i], y[i], x[j], y[j]);
// int mid_x2 = (x[i] + x[j]);
// int mid_y2 = (y[i] + y[j]);
// ld need_slope;
// if(slope == INF) {
// need_slope = 0;
// }
// else {
// need_slope = -1 / slope;
// }
//
// Simon need = {need_slope, dist, mid_x2, mid_y2};
//// for(Simon ceva : v) {
//// if(ceva == need) {
//// answer++;
//// break;
//// }
//// }
//
// int itl = lower_bound(v + 1, v + ind + 1, need) - v;
// if(itl <= ind && v[itl] == need) {
// answer++;
// }
// }
// }
for(int i = 1; i <= ind; i++) {
Simon here = v[i];
here.slope = (here.slope == INF ? 0 : -1 / here.slope);
int itl = lower_bound(v + 1, v + ind + 1, here) - v;
if(itl <= ind && v[itl] == here) {
answer++;
}
}
fout << answer / 2 << '\n';
return 0;
}