Pagini recente » Cod sursa (job #1051538) | Cod sursa (job #1320466) | Cod sursa (job #297922) | Cod sursa (job #1332973) | Cod sursa (job #2202868)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
using namespace std;
ifstream in("trapez.in");
ofstream out("trapez.out");
const int maxN = 1001,
maxPante = 1000001;
struct punct {
int x, y;
};
struct panta {
long long x, y;
};
punct a[maxN];
panta p[maxPante];
int k = 0, x = 0;
void calcPante(int n) {
for(int i = 1; i < n; i++)
for(int j = i+1; j <= n; j++) {
if(a[i].x == a[j].x) x++;
else {
p[++k].x = abs(a[j].x - a[i].x);
p[k].y = abs(a[j].y - a[i].y);
}
}
}
bool panteEgale(const panta &b, const panta &c) {
if(b.x * c.y == b.y * c.x) return true;
else return false;
}
bool comp(const panta &b, const panta &c) {
if(b.x * c.y < b.y * c.x) return true;
else return false;
}
long long comb(int n) {
return 1LL * (n*(n-1))/2;
}
int main()
{
int n, pEg = 1;
long long sol = 0;
in >> n;
for(int i = 1; i <= n; i++)
in >> a[i].x >> a[i].y;
calcPante(n);
sort(p+1, p+k+1, comp);
for(int i = 2; i < k; i++) {
if(panteEgale(p[i], p[i-1]))
pEg++;
else {
if(pEg > 1)
sol += comb(pEg),
pEg = 1;
else pEg = 1;
}
}
if(pEg > 1) sol += comb(pEg);
if(x > 1) sol += comb(x);
out << sol;
return 0;
}