Cod sursa(job #1226326)

Utilizator AndreosAndrei Otetea Andreos Data 5 septembrie 2014 10:30:50
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.45 kb
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
#define INF 1.e9
#define eps 1.e-14
const int nmax=1005;
class POINT
{
    private:
        double x,y;
    public:
        POINT(){x=y=0;}
        POINT(const POINT&other)
        {
            x=other.x;
            y=other.y;
        }
        double getx(){return x;}
        double gety(){return y;}
        void set(int x0,int y0)
        {
            x=x0;
            y=y0;
        }
        double panta(const POINT&other)
        {
            if(fabs(x-other.x)<eps)
                return INF;
            return (other.y-y)/(other.x-x);
        }
    friend bool operator==(const POINT&p1,const POINT&p2)
    {
        return(fabs(p1.x-p2.x)<eps && fabs(p1.y-p2.y)<eps);
    }
};
POINT v[1005];
double pan[1000005];
int main()
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    int i,j,l=0,rez=0,tx,ty,nr=0;
    short int n;
    scanf("%hd",&n);
    for (i=1;i<=n;i++)
    {
        scanf("%d%d",&tx,&ty);
        v[i].set(tx,ty);
    }
    for (i=1;i<n;i++)
    {
        for (j=i+1;j<=n;j++)
        {
            l++;
            pan[l]=v[i].panta(v[j]);
        }
    }
    sort(pan+1,pan+l+1);
    for (i=2;i<=l;i++)
    {
        if (pan[i]==pan[i-1])
        {
            nr++;
            rez=rez+nr;
        }
        else
            nr=0;
    }
    printf("%d",rez);
    return  0;
}