Cod sursa(job #3258058)

Utilizator Mihai_OctMihai Octavian Mihai_Oct Data 20 noiembrie 2024 18:28:21
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.38 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("trapez.in");
ofstream fout("trapez.out");
struct Punct {
    double x, y;

    Punct(double _x = 0, double _y = 0) {
        x = _x;
        y = _y;
    }
};
struct Segment {
    struct Coef {
        double a, b, c;

        Coef(double _a = 0, double _b = 0, double _c = 0) {
            a = _a;
            b = _b;
            c = _c;
        }
    };

    Punct p1, p2;
    Coef coef;

    Segment(Punct _p1, Punct _p2) {
        p1 = _p1;
        p2 = _p2;
    }

    Coef GetCoef() {
        double a = p1.y - p2.y;
        double b = p2.x - p1.x;
        double c = p1.x * (p2.y - p1.y) - p1.y * (p2.x - p1.x);
        return Coef(a, b, c);
    }
};
unordered_map<long double, int> fr;
int n, r, i, j, h, dx, dy;
Punct v[1002];

int main()  {
    fin >> n;

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

    for(i = 1; i <= n; i++) {
        for(j = i + 1; j <= n; j++) {
            dx = v[i].x - v[j].x;
            dy = v[i].y - v[j].y;

            if(dx == 0) h++;
            else {
                long double panta = (long double)dx / (long double)dy;

                fr[panta]++;
            }
        }
    }

    if((h * (h - 1)) / 2 > 0) r = (h * (h - 1)) / 2;

    for(auto it : fr) r += (it.second * (it.second - 1)) / 2;

    fout << r;

    return 0;
}