Cod sursa(job #2091456)

Utilizator cristii2000cristiiPanaite Cristian cristii2000cristii Data 19 decembrie 2017 18:28:56
Problema Trapez Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.91 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#define Punct pair <ll, ll>
#define X first
#define Y second
#define Max 1005
#define ll long long

using namespace std;

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

Punct puncte[Max];
ll n;
ll suma;
ll inf;
ll counterSlope;
struct Slope
{
    ll numarator, numitor;
} Pante[5000000];

void citire()
{
    in >> n;
    for (ll i = 0; i < n; i++)
    {
        in >> puncte[i].X >> puncte[i].Y;
    }
}

ll comparator(Slope a, Slope b)
{
    return (a.numarator * b.numitor) < (a.numitor * b.numarator);
}

void SlopeConstruction()
{
    for(ll i = 0; i < n - 1; i++)
        for(ll j = i + 1; j < n; j++)
        {
            if(puncte[i].X - puncte[j].X == 0)
            {
                inf++;
                continue;
            }
            if(puncte[i].X > puncte[j].X)
            {
                Pante[counterSlope].numarator = puncte[i].Y - puncte[j].Y;
                Pante[counterSlope].numitor = puncte[i].X - puncte[j].X;
                counterSlope++;
                counterSlope++;
            }
            else
            {
               Pante[counterSlope].numarator = puncte[j].Y - puncte[i].Y;
               Pante[counterSlope].numitor = puncte[j].X - puncte[i].X;
               counterSlope++;
            }
        }
    sort(Pante, Pante + counterSlope, comparator);
}

void NumarareTrapeze()
{
    int lg = 1;
    for(ll i = 1; i < counterSlope; i++)
            if((Pante[i].numarator * Pante[i-1].numitor) == (Pante[i].numitor * Pante[i-1].numarator))
                lg++;
            else
            {
                suma += (lg * (lg - 1)) / 2, lg = 1;
            }
        suma += (lg * (lg - 1)) / 2;
        suma += (inf * (inf - 1)) / 2;
}

int main()
{
    citire();
    SlopeConstruction();
    NumarareTrapeze();
    out << suma;
    return 0;
}