Cod sursa(job #1984294)

Utilizator FredyLup Lucia Fredy Data 24 mai 2017 14:15:03
Problema Trapez Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

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

#define lim 1005
#define inf 1000000
int n;
struct pct{int x,y;} v[lim];
struct panta{int a,b;} m[lim*lim],aux;
long long rez=0;

bool egal(panta q, panta r)
{
    if(1LL*q.a*r.b==1LL*q.b*r.a)
        return true;
    return false;
}

bool cmp(panta q, panta r)
{
    if(1LL*q.a*r.b<=1LL*q.b*r.a)
        return 1;
    return 0;
}


int main()
{
    fin>>n;
    for(int i=1; i<=n; i++)
        fin>>v[i].x>>v[i].y;

    int k=0;
    for(int i=1; i<n; i++)
        for(int j=i+1; j<=n; j++)
        {
            aux.a=v[j].y-v[i].y;
            aux.b=v[j].x-v[i].x;
            m[++k]=aux;
        }

    sort(m+1,m+k+1,cmp);

    int i=1;
    while(i<=k)
    {
        int j=i,l=0;
        while(j<=k && egal(m[i],m[j]))
            j++,l++;
        rez=rez+1LL*l*(l-1)/2;
        i++;
    }
    fout<<rez;

    fin.close();
    fout.close();
    return 0;
}