Cod sursa(job #76098)

Utilizator DastasIonescu Vlad Dastas Data 7 august 2007 22:47:52
Problema Trapez Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <cstdio>
#include <algorithm>
#include <cmath>

const int maxn = 1000;
const double eps = 0.0000000000000001;
const double inf = 2000000002.0;

FILE *in = fopen("trapez.in","r"), *out = fopen("trapez.out","w");

struct punct
{
    int x, y;
};

int n;
punct a[maxn];

int k;

struct dbl
{
    double p;
};

dbl p[maxn*maxn];

void read()
{
    fscanf(in, "%d", &n);

    for ( int i = 0; i < n; ++i )
        fscanf(in, "%d %d", &a[i].x, &a[i].y);
}

void go()
{
    for ( int i = 0; i < n; ++i )
        for ( int j = i + 1; j < n; ++j )
        {
            if ( a[i].x == a[j].x )
                p[k++].p = inf;
            else
                p[k++].p = (double)( a[i].y - a[j].y ) / ( a[i].x - a[j].x );
        }
}

bool operator<(const dbl &x, const dbl &y)
{
    return x.p - y.p < eps;
}

int main()
{
    read();
    go();
    std::sort(p, p+k);

    long long cnt = 0;

    for ( int i = 1; i < k; ++i )
        if ( p[i].p - p[i-1].p < eps )
            ++cnt;

    fprintf(out, "%lld\n", cnt);

	return 0;
}