Pagini recente » Cod sursa (job #1096394) | Cod sursa (job #2774384) | Cod sursa (job #899597) | Cod sursa (job #1632518) | Cod sursa (job #2202870)
#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;
const double eps = 1e-9;
struct punct {
int x, y;
};
punct a[maxN];
double 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] = (double)(a[i].y - a[j].y)/(a[i].x - a[j].x);
}
}
bool eg(double x, double y) {
if(fabs(x-y) < eps) return true;
else return false;
}
long long comb(int n) {
return 1LL * (n*(n-1))/2;
}
int main()
{
ios_base::sync_with_stdio(false);
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);
for(int i = 1; i < k; i++) {
if(eg(p[i], p[i+1])) {
pEg++;
} else {
sol += comb(pEg);
pEg = 1;
}
}
if(pEg > 1) sol += comb(pEg);
if(x > 1) sol += comb(x);
out << sol;
return 0;
}