Cod sursa(job #517394)

Utilizator Magnuscont cu nume gresit sau fals Magnus Data 28 decembrie 2010 17:00:19
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

int v[2][1001],n,p,s,c,x,y;
double ctg[1000001],cat;

int main()
{
    int i,j;
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    scanf("%d",&n);
    for (i=1;i<=n;++i) scanf("%d%d",&v[0][i],&v[1][i]);
    for (i=1;i<=n;++i)
        for (j=i+1;j<=n;++j)
        {
            ++c;
            x=v[0][i]-v[0][j];
            y=v[1][i]-v[1][j];
            if (y<0)
            {
                x=-x;
                y=-y;
            }
            else if ((y==0)&&(x<0)) x=-x;
            if (y!=0) ctg[c]=(double)x/y;
            else ctg[c]=2000000001;
        }
    sort(ctg+1,ctg+c+1);
    for (i=2;i<=c;++i)
    {
        if (ctg[i]==ctg[i-1]) ++p;
        else
        {
            s+=p*(p+1)/2;
            p=0;
        }
    }
    if (p) s+=p*(p+1)/2;
    printf("%d",s);
    return 0;
}