Cod sursa(job #76108)

Utilizator DastasIonescu Vlad Dastas Data 7 august 2007 23:16:32
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <cstdio>
#include <algorithm>
#include <cmath>

const int maxn = 1000;
const double eps = 0.000000000000001;
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;
double 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++] = inf;
            else
                p[k++] = (double)( a[i].y - a[j].y ) / ( a[i].x - a[j].x );
        }
}


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

    int cnt = 1;
    int r = 0;

    for ( int i = 1; i < k; ++i )
    {
        if ( p[i] - p[i-1] < eps )
            ++cnt;
        else
            r += (cnt*(cnt-1))/2, cnt = 1;
    }

    fprintf(out, "%d\n", r);

	return 0;
}