Cod sursa(job #1342736)

Utilizator petru13Stinga Petru petru13 Data 14 februarie 2015 14:28:41
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include<cstdio>
using namespace std;
struct mat{int l,c;};
mat m[1000];
struct pant{int y,x;};
pant d[1000];
int trap,n,i,j,a,q,w,o,p;
int cmmdc(int a, int b)
{
    int r;
    while (b) {
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
int main()
{
    int r=0;
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d%d",&m[i].l,&m[i].c);
    }
    o=1;
    for(i=1;i<=n-1;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            w=m[j].l-m[i].l;
            q=m[j].c-m[i].c;
            if(w<0)
                w=w*(-1);
            if(q<0)
                q=q*(-1);
            p=cmmdc(w,q);
            d[o].x=w/p;
            d[o].y=q/p;
            o++;
        }
    }
    for(i=1;i<=o-1;i++)
        for(j=i+1;j<=o;j++)
            if(d[i].x==d[j].x&&d[i].y==d[j].y)
                trap++;
    printf("%d",trap/2);
    return 0;
}