Cod sursa(job #1095856)

Utilizator IronWingVlad Paunescu IronWing Data 1 februarie 2014 01:09:26
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <fstream>
#include <algorithm>
#define LL long long
using namespace std;
ifstream in("trapez.in"); ofstream out("trapez.out");
const int Nmax=1002;
int n,m;
LL nr=1,tot;
struct art {LL x,y;} P[Nmax];
art C[Nmax*(Nmax-1)/2];
bool egal(art &a, art &b)
{   return (a.x*b.y==b.x*a.y);}
bool cmp(const art &a, const art &b)
{   if (a.x*b.y==b.x*a.y) return 0;
    bool r=(a.x*b.y<b.x*a.y);
    if (b.y<0) r=!r;
    if (a.y<0) r=!r;
    return r;
}
int main ()
{   in>> n;
    for(int i=1; i<=n; ++i) in>>P[i].x>>P[i].y;
    for(int i=1; i<n; ++i)
        for(int j=i+1; j<=n; ++j)
            {C[++m].x=P[i].x-P[j].x; C[m].y=P[i].y-P[j].y;}
    sort(C+1,C+m+1,cmp);
    for(int i=2; i<=m; ++i)
        if(egal(C[i-1],C[i])) ++nr;
            else {tot += (nr*nr-nr)/2; nr=1;}
    tot += (nr*nr-nr)/2;
    out<<tot<<'\n'; out.close(); return 0;
}