Cod sursa(job #2626177)

Utilizator Edwuard99Diaconescu Vlad Edwuard99 Data 6 iunie 2020 12:21:40
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.48 kb
#include <cstdio>
#include <algorithm>
#include <cmath>
#define Nmax 1005
#define eps 1.e-4
 
using namespace std;
 
struct pc
{
    double x,y;
    bool operator == (const pc A)
    {
        return (fabs(A.x-x)<eps && fabs(A.y-y)<eps);
    }
    bool operator <(const pc A)
    {
        if(fabs(A.x-x)<eps)
            return y<A.y;
        return x<A.x;
    }
    bool operator >(const pc A)
    {
        if(fabs(A.x-x)<eps)
            return y>A.y;
        return x>A.x;
    }
};
pc v[Nmax];
int N;
 
inline bool Cmp(const pc A, const pc B)
{
    if(fabs(A.x-B.x)<eps)
        return (B.y-A.y>=eps);
    return (B.x-A.x>=eps);
}
 
inline bool BSearch(pc A)
{
    int st=1,dr=N,mij;
    while(st<=dr)
    {
        mij=((st+dr)>>1);
        if(v[mij]==A)
            return true;
        if(v[mij]<A)
            st=mij+1;
        else
            dr=mij-1;
    }
    return false;
}
 
int main()
{
    int i,j,sol=0;
    pc a,b;
    freopen ("patrate3.in","r",stdin);
    freopen ("patrate3.out","w",stdout);
    scanf("%d", &N);
    for(i=1;i<=N;++i)
        scanf("%lf%lf", &v[i].x,&v[i].y);
 
    sort(v+1,v+N+1,Cmp);
 
    for(i=1;i<N;++i)
        for(j=i+1;j<=N;++j)
        {
            a.x=v[i].x+v[i].y-v[j].y;
            a.y=v[i].y+v[j].x-v[i].x;
            b.x=v[i].y+v[j].x-v[j].y;
            b.y=v[j].x+v[j].y-v[i].x;
            if(BSearch(a) && BSearch(b))
                ++sol;
        }
    printf("%d\n", sol/2);
}