Pagini recente » Cod sursa (job #2713548) | Cod sursa (job #1872156) | Cod sursa (job #1590597) | Cod sursa (job #1617921) | Cod sursa (job #2202879)
#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-15;
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;
}
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);
for(int i = 1; i <= k; i++) {
pEg = 0;
while(eg(p[i], p[i+1]))
i++, pEg++;
sol += (pEg * (pEg+1))/2;
}
if(x > 1) sol += (x * (x-1))/2;
out << sol;
return 0;
}