Cod sursa(job #869575)

Utilizator ericptsStavarache Petru Eric ericpts Data 1 februarie 2013 20:00:43
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

#define eps 0.0000001

struct point
{
public:
    int x,y;
    point()
    {
        x = y = 0;
    }
}pct[1005];
double line[1002*1002];

bool comp(const double &a,const double &b)
{
    return fabs(a-b) <= eps;
}

int main()
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    int i,j,n;
    int dx,dy;
    int k;
    int cr = 0;
    unsigned int show = 0;
    scanf("%d\n",&n);

    for(i=1;i<=n;++i)
        scanf("%d %d\n",&pct[i].x,&pct[i].y);

    for(i=1  ;i<=n;++i)
    for(j=i+1;j<=n;++j)
    {
        dx = pct[j].x-pct[i].x;
        dy = pct[j].y-pct[i].y;
        if(!dx)
        {
            dx = 1;
            dy = 1 << 30;
        }
        line[++cr] = double(dy)/dx;
    }
    sort(line+1,line+cr+1,comp);
    k=1;
    for(i=2;i<=cr;++i)
    {
        if(fabs(line[i] - line[i-1]) <= eps)
            ++k;
        else
        {
            show += (k * (k-1)) / 2;
            k = 1;
        }
    }
    show += (k * (k-1)) / 2;
    printf("%u\n",show);
    return 0;
}