Cod sursa(job #2634016)

Utilizator stefan.popescuPopescu Stefan stefan.popescu Data 9 iulie 2020 16:25:50
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream in ("trapez.in");
ofstream out("trapez.out");
int n, x, y;
const int oo=2000000002;
vector <pair <int, int> > puncte;
vector <long double> mapp;
inline long double getSlope(int & x1, int & y1, int & x2, int & y2)
{
    if(x1==x2) return oo;
    return ((long double)y2-y1)/((long double)x2-x1);
}
int rez, lenact;
int main()
{
    in>>n;
    mapp.reserve(n*(n-1)/2);
    puncte.reserve(n);
    for(int i=1; i<=n; i++)
    {
        in>>x>>y;
        for(auto & val : puncte)
            mapp.push_back(getSlope(x, y, val.first, val.second));

        puncte.push_back({x, y});
    }

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

    lenact++;
    for(int i=1; i<mapp.size(); i++)
    {
        if(mapp[i]==mapp[i-1]) lenact++;
        else lenact=1;
        rez+=lenact-1;
    }
    out<<rez;
    return 0;
}