Cod sursa(job #2634010)

Utilizator stefan.popescuPopescu Stefan stefan.popescu Data 9 iulie 2020 16:17:19
Problema Trapez Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <unordered_map>
using namespace std;
ifstream in ("trapez.in");
ofstream out("trapez.out");
int n, x, y;
const int oo=2000000002;
vector <pair <int, int> > puncte;
unordered_map <long double, int> 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;
int main()
{
    in>>n;
    for(int i=1; i<=n; i++)
    {
        in>>x>>y;
        for(auto & val : puncte)
        {
            auto itr=mapp.find(getSlope(x, y, val.first, val.second));
            if(itr==mapp.end()) mapp.insert({getSlope(x, y, val.first, val.second), 1});
            else itr->second++;
        }
        puncte.push_back({x, y});
    }
    //cout<<mapp.size();
    for(auto x : mapp)
    {
        rez+=x.second*(x.second-1)/2;
    }
    out<<rez;
    return 0;
}