Cod sursa(job #1987643)

Utilizator llalexandruLungu Alexandru Ioan llalexandru Data 31 mai 2017 14:37:49
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <fstream>
#include <algorithm>
#define NM 1005
#define INF 2000000005

using namespace std;

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

struct punct{int x, y;};

punct P[NM];
double V[NM*NM];
int nr, n, sum;

int modul (int x)
{
    if (x<0)
        return -1*x;
    return x;
}

int main()
{
    int i, j, ok;
    double x, y;
    fin>>n;
    for (i=1; i<=n; i++)
    {
        fin>>P[i].x>>P[i].y;
    }
    for (i=1; i<=n; i++)
    {
        for (j=i+1; j<=n; j++)
        {
            nr++;
            x=P[i].x-P[j].x;
            y=P[i].y-P[j].y;
            if (x==0)
                V[nr]=INF;
            else
                V[nr]=y/x;
        }
    }
    sort(V+1, V+nr+1);
    int l=1;
    for (i=2; i<=nr; i++)
    {
        if (V[i]==V[i-1])
        {
            l++;
        }
        else
        {
            sum+=l*(l-1)/2;
            l=1;
        }
    }
    sum+=l*(l-1)/2;
    fout<<sum;
    return 0;
}