Cod sursa(job #2422275)

Utilizator oogaboogauvuvwevwevwe onyetenyevwe ugwemubwem ossas oogabooga Data 18 mai 2019 12:14:33
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <bits/stdc++.h>

using namespace std;

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

struct pct{
    double x,y;
};

int nrPct,r,t=1;
pct p[1005];
vector <double> panta;

int main(){
    ios::sync_with_stdio(0);

    in>>nrPct;

    for(int i = 1; i <= nrPct; ++i) in>>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;

    out<<r + (t * (t - 1)) / 2;

    return 0;
}