Cod sursa(job #914551)

Utilizator stefan.friptuPetru Stefan Friptu stefan.friptu Data 14 martie 2013 11:37:16
Problema Patrate 3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.27 kb
#include <cstdio>
#include <algorithm>
#include <cmath>

#define eps 1.e-6

using namespace std;

struct POINT {
    double x;
    double y;
};

POINT p[1001];
double aux1,aux2;
POINT A,B;
long i,n,j,patrate;

long cmp (POINT a, POINT b)
{
    if(fabs(a.x-b.x)<eps)
        return a.y<b.y;
    return a.x<b.x;
}

long bs (POINT pct)
{
    int st,dr,med;
    st=1; dr=n;
    while(st<=dr)
        {
            med=(st+dr)/2;
            if(fabs(p[med].x-pct.x)<=eps && fabs(p[med].y-pct.y)<=eps)
                return 1;
            if(cmp(pct,p[med]))
                dr=med-1;
            else
                st=med+1;
        }
    return 0;
}

int main () {

    freopen ("patrate3.in","r",stdin);
    freopen ("patrate3.out","w",stdout);

    scanf("%ld",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%lf%lf",&aux1,&aux2);
        p[i].x=aux1;
        p[i].y=aux2;
    }

    sort(p+1,p+n+1,cmp);

    for(i=1;i<=n;i++)
        for(j=i+1;j<=n;j++)
        {
            A.x=p[i].x+p[i].y-p[j].y;
            A.y=p[i].y+p[j].x-p[i].x;
            B.x=p[i].y+p[j].x-p[j].y;
            B.y=p[j].x+p[j].y-p[i].x;
            if(bs(A) && bs(B))
                patrate++;
        }
    printf("%ld\n",patrate/2);
    return 0;
}