Cod sursa(job #2404578)

Utilizator AlexandruabcdeDobleaga Alexandru Alexandruabcde Data 13 aprilie 2019 08:52:00
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <fstream>
#include <algorithm>
#define INF 0x3f3f3f3f

using namespace std;

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

struct punct
{
    double x, y;
};

int n;

punct a[1005];

double pante[1000005];

int ans = 0;

int main()
{
    f >> n;

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

    int vf = 0;

    for (int i = 1; i <= n; ++i)
    {
        for (int j = i + 1; j <= n; ++j)
        {
            if (a[i].x == a[j].x)
            {
                pante[++vf] = INF;
            }
            else
            {
                pante[++vf] = (a[i].y - a[j].y) / (a[i].x - a[j].x);
            }
        }
    }

    sort(pante + 1, pante + vf + 1);

    int nr = 1;

    for (int i = 2; i <= vf; ++i)
    {
        if (pante[i] == pante[i-1])
        {
            nr++;
        }
        else
        {
            ans = ans + nr * (nr - 1) / 2;
            nr = 1;
        }
    }

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