Cod sursa(job #2595415)

Utilizator AlexandruabcdeDobleaga Alexandru Alexandruabcde Data 7 aprilie 2020 18:21:19
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <fstream>
#include <algorithm>
#include <vector>
#define INF 0x3f3f3f3f

using namespace std;

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

struct punct
{
    double x, y;
};
punct a[1005];

int N;

vector <double> panta;

void Read ()
{
    f >> N;

    for (int i = 1; i <= N; ++i)
        f >> a[i].x >> a[i].y;
}

void Precalculare ()
{
    for (int i = 1; i <= N; ++i)
        for (int j = i + 1; j <= N; ++j)
        {
            if (a[i].x == a[j].x) panta.push_back(INF);
            else
            {
                panta.push_back((a[i].y - a[j].y) / (a[i].x - a[j].x));
            }
        }

    sort(panta.begin(), panta.end());
}

void Solve ()
{
    int nr = 1;

    long long ans = 0;

    for (int i = 1; i < panta.size(); ++i)
    {
        if (panta[i] == panta[i-1]) ++ nr;
        else
        {
            ans = ans + (nr * (nr-1)) / 2;

            nr = 1;
        }
    }

    ans = ans + nr * (nr - 1) / 2;

    g << ans << '\n';
}

int main()
{
    Read ();
    Precalculare();
    Solve();

    return 0;
}