Cod sursa(job #2202877)

Utilizator AndreiVisoiuAndrei Visoiu AndreiVisoiu Data 10 mai 2018 11:31:26
Problema Trapez Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#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-7;
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;
}