Cod sursa(job #1649046)

Utilizator EberardoVladianu Cosmin Eberardo Data 11 martie 2016 12:25:07
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.71 kb
#include <fstream>
#include <algorithm>

using namespace std;

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

struct punct
{
    long long x,y;
    punct(long long x=0, long long y=0):
        x(x),y(y)
        {
        }
    bool operator<(const punct &punct2) const
    {
        if(x==punct2.x)
            return y<punct2.y;
        else
            return x<punct2.x;
    }
}puncte[1002];

struct panta
{
    long long x,y;
    panta(long long x=0, long long y=0):
        x(x),y(y)
        {
        }
    bool operator<(const panta &punct2) const
    {
        return x*punct2.y<punct2.x*y;
    }
    bool operator==(const panta &punct2) const
    {
        return x*punct2.y==punct2.x*y;
    }
};

long long modul(long long a)
{
    if(a<0)
        return -a;
    return a;

}

int n;
int contor=0;

panta pante[510000];

unsigned long long havem_haur;
unsigned long long ll=1,l2l=2;

void citire()
{
    int i,a,b;
    fin>>n;
    for(i=1;i<=n;i++)
    {
        fin>>puncte[i].x>>puncte[i].y;
    }
}

void creare_pante()
{
    int i,j;
    for(i=1;i<n;i++)
        for(j=i+1;j<=n;j++)
        {
            pante[++contor].y=puncte[j].y-puncte[i].y;
            pante[contor].x=puncte[j].x-puncte[i].x;
        }
}

void rezolvare()
{
    int i;
    unsigned long long c=1;
    sort(puncte+1,puncte+n+1);
    creare_pante();
    sort(pante+1,pante+contor+1);
    for(i=2;i<=contor;i++)
    {
        if(pante[i]==pante[i-1])
            c+=ll;
        else
        {
            havem_haur+=(c*(c-ll))/2;
            c=ll;
        }
    }
}

int main()
{
    citire();
    rezolvare();
    fout<<havem_haur;
    return 0;
}