Cod sursa(job #2410207)

Utilizator AntoniuFicAntoniu Ficard AntoniuFic Data 19 aprilie 2019 20:05:02
Problema Trapez Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <cmath>

using namespace std;

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

map<pair<int, int>, int>slopes;
multiset<pair<int, int>>points;

int n;

int comb(int x){
    return x*(x-1)/2;
}

int cmmdc(int x, int y){
    if(y == 0)
        return x;
    return cmmdc(y, x%y);
}

int main() {
    pair<int, int>point;
    int rez = 0;
    f>>n;
    for (int i = 0; i < n; ++i) {
        f>>point.first;
        f>>point.second;
        for (auto it:points) {
            int c = cmmdc(it.second - point.second, it.first - point.first);
            ++slopes[{(it.second - point.second) / c, (it.first - point.first) / c}];
        }
        points.insert(point);
    }
    for (auto it:slopes) {
        rez+=comb(it.second);
    }
    g<<rez;
    return 0;
}