Cod sursa(job #2204558)

Utilizator Alex_BubBuburuzan Alexandru Alex_Bub Data 16 mai 2018 15:09:03
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("trapez.in");
ofstream fout("trapez.out");

const double E = 1e-15;

vector <double> p;

struct st {int x, y;} v[1001];

double panta(int i, int j) {
    return (double)(v[i].y - v[j].y) / (v[i].x - v[j].x);
}

int main()
{
    int n, nrx = 0, ans = 0;

    fin >> n;

    for(int i = 0; i < n; i++)
        fin >> v[i].x >> v[i].y;

    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            if(v[i].x == v[j].x)
                nrx++;
            else
                p.push_back(panta(i, j));
        }
    }

    ans += nrx * (nrx - 1) >> 1;

    sort(p.begin(), p.end());

    for(vector<double> :: iterator it = p.begin(); it != p.end(); it++) {
        int nr = 1;

        while(fabs(*it - *(it + 1)) < E)
            it++, nr++;

        ans += nr * (nr - 1) >> 1;
    }

    fout << ans;

    fin.close();
    fout.close();

    return 0;
}