Cod sursa(job #1166901)

Utilizator chiriacandrei25Chiriac Andrei chiriacandrei25 Data 3 aprilie 2014 22:27:40
Problema Patrate 3 Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <cstdio>
#include <vector>
#include <cmath>
#define Nmax 1005
#define P 100021
#define eps 0.00001

using namespace std;

struct pc
{
    double x,y;
    bool operator == (const pc A)
    {
        return (fabs(A.x-x)<eps && fabs(A.y-y)<eps);
    }
};
pc v[Nmax];
vector <pc> L[P];

inline void AddHash(pc A)
{
    int i=((int)A.x*10000+(int)A.y*10000+1000*P)%P;
    L[i].push_back(A);
}

inline bool CautaHash(pc A)
{
    int i=((int)A.x*10000+(int)A.y*10000+1000*P)%P;
    vector <pc>::iterator it;
    for(it=L[i].begin();it!=L[i].end();++it)
        if(*it==A)
            return true;
    return false;
}

int main()
{
    int i,N,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);
        AddHash(v[i]);
    }
    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(CautaHash(a) && CautaHash(b))
                ++sol;
        }
    printf("%d\n", sol/2);
}