Cod sursa(job #2916319)

Utilizator alin.gabrielAlin Gabriel Arhip alin.gabriel Data 29 iulie 2022 07:07:23
Problema Trapez Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <fstream>
#include <algorithm>
using namespace std;

#define N 1000
#define NM 499500

typedef long double ld;

ifstream f("trapez.in");
ofstream g("trapez.out");

struct point {
    ld x, y;

    bool operator == (const point& a) const {
        return y / x == a.y / a.x ;
    }
};

point v[N], m[NM];

//   a.x     b.x
//   ---  <  ---
//   a.y     b.y
bool cmp(point a, point b) {
    return a.x * b.y < a.y * b.x;
}

point slope(point a, point b) {
    return {b.x - a.x, b.y - a.y};
}

int main() {
    int n, idx = 0;

    f >> n;
    for (int i = 0; i < n; i++) {
        f >> v[i].x >> v[i].y;
        for (int j = 0; j < i; j++)
            m[idx++] = slope(v[i], v[j]);
    }

    sort(m, m + idx, cmp);

    int s = 0, cnt = 1;
    for (int i = 0 ; i < idx; i++)
        if (m[i] == m[i + 1])
            cnt++;
        else {
            s += cnt * (cnt - 1);
            cnt = 1;
        }

    g << (s >> 1);
    return 0;
}