Cod sursa(job #914227)

Utilizator alecsandrualex cuturela alecsandru Data 13 martie 2013 23:03:44
Problema Patrate 3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.32 kb
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#define eps 1.e-6
using namespace std;
struct POINT
{
    double x,y;
};
POINT a[1100];
int n,i,j;
bool cmp(POINT const &x,POINT const &y)
{
    if(fabs(x.x-y.x)<eps)
    {
        return x.y<y.y;
    }
    return x.x<y.x;
}
int bs(POINT X)
{
    int st,dr,med;
    st=1;
    dr=n;
    while(st<=dr)
    {
        med=((dr-st)>>1)+st;
        if(fabs(a[med].x-X.x)<eps&&fabs(a[med].y-X.y)<eps)
        {
            return 1;
        }
        if(cmp(X,a[med]))
        {
            dr=med-1;
        }
        else
            st=med+1;
    }
    return 0;
}
int main()
{
    double v1,v2;
    POINT A,B,X,Y;
    int rez=0;
    freopen("patrate3.in","r",stdin);
    freopen("patrate3.out","w",stdout);
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%lf%lf",&v1,&v2);
        A.x=v1;
        A.y=v2;
        a[i]=A;
    }
    sort(a+1,a+n+1,cmp);
    for(i=1;i<n;i++)
        for(j=i+1;j<=n;j++)
        {
            A=a[i];
            B=a[j];
            X.x=A.x+A.y-B.y;
            X.y=A.y+B.x-A.x;
            Y.x=B.x+A.y-B.y;
            Y.y=B.y+B.x-A.x;
            if(bs(X)&&bs(Y))
            {
                rez++;
            }
        }
    printf("%d",rez/2);
    return 0;
}