Cod sursa(job #1996135)

Utilizator FlorinHajaFlorin Gabriel Haja FlorinHaja Data 30 iunie 2017 12:21:53
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <fstream>
#include <iostream>
#include <unordered_map>

using namespace std;

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

const int nmax = 1005;
int n, i, j, x, y;
double pnt;
struct punct {
    int x, y;
}v[1005];
long long sol;
unordered_map <double, int> cnt;

int main() {
    f >> n;
    for (i = 1; i <= n; i++) {
        f >> x >> y;
        v[i] = {x,y};
    }
    for (i = 1; i <= n; i++) {
        for (j = i+1; j <= n; j++) {
            if (v[j].x == v[i].x) {
                if (v[j].y > v[i].y)
                    pnt = -2e9+5;
                else pnt = -2e9+6;
            }
            else pnt = (double)(v[j].y-v[i].y)/(v[j].x-v[i].x);
            cnt[pnt]++;
        }
    }
    for (i = 1; i <= n; i++) {
        for (j = i+1; j <= n; j++) {
            if (v[j].x == v[i].x) {
                if (v[j].y > v[i].y)
                    pnt = -2e9+5;
                else pnt = -2e9+6;
            }
            else pnt = (v[j].y-v[i].y)/(v[j].x-v[i].x);
            x = cnt[pnt];
            if (x)
                sol += (x*(x-1))/2;
            cnt[pnt] = 0;
        }
    }
    g << sol;
    return 0;
}