Cod sursa(job #2623383)

Utilizator paulconst1Constantinescu Paul paulconst1 Data 3 iunie 2020 01:28:53
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("trapez.in");
ofstream fout("trapez.out");

struct pct{
    double x,y;
}p[1005];

int nrPct,r,t=1;
vector <double> panta;

int main()
{
    fin>>nrPct;
    for(int i = 1; i <= nrPct; ++i)
        fin>>p[i].x>>p[i].y;
    for(int i = 1; i < nrPct; ++i)
    for(int j = i + 1; j <= nrPct; ++j)
        if(p[j].x - p[i].x == 0)
        panta.push_back(INT_MAX - 1);
        else
        panta.push_back((p[j].y - p[i].y) / (p[j].x - p[i].x));
    sort(panta.begin(), panta.end());
    for(int i = 1; i < panta.size(); ++i)
        if(panta[i] == panta[i - 1])
         ++t;
        else
            r += (t * (t - 1)) / 2, t = 1;
    fout<<r + (t * (t - 1)) / 2;
}