Cod sursa(job #1649425)

Utilizator Flor1nC23Condrovici Florin Flor1nC23 Data 11 martie 2016 13:37:35
Problema Trapez Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("trapez.in");
ofstream g("trapez.out");
long long nr,c=1,el;
int n;
struct pct{int x,y;} a[1002],pante[50502];
bool cmp(pct a,pct b)
{
    if(a.x<b.x)
        if(a.y<b.y)return true;
    return false;
}
bool cmppante(pct a,pct b)
{
    if(a.x*b.y<a.y*b.x) return true;
        return false;
}
void citire()
{int i,j;
    f>>n;
    for( i=1;i<=n;i++)
    f>>a[i].x>>a[i].y;
    sort(a+1,a+n+1,cmp);
    for(i=1;i<n;i++)
        for(j=i+1;j<=n;j++)
    {el++;

        pante[el].y=a[j].y-a[i].y;
        pante[el].x=a[j].x-a[i].x;
    }
    sort(pante+1,pante+el+1,cmppante);

}

void rez()
{int i;
    citire();
    for(i=1;i<el;i++)
        if(pante[i].x*pante[i+1].y==pante[i].y*pante[i+1].x)
            c+=1;
            else
            {
                nr+=(c*(c-1))/2;
                c=1;
            }
      g<<nr;
}

int main()
{
    rez();

    return 0;
}