Cod sursa(job #1991263)

Utilizator facelessIonut Balauca faceless Data 15 iunie 2017 22:19:09
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <bits/stdc++.h>
#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 nod(int x)
{
    if(x<0)
        return -1*x;
    else
        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<=n;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;}