Cod sursa(job #1166964)

Utilizator andreiiiiPopa Andrei andreiiii Data 4 aprilie 2014 00:23:36
Problema Patrate 3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.77 kb
#include <algorithm>
#include <fstream>
#include <vector>
#include <string>
#define ll long long

using namespace std;

const int N=1005, MOD=666013;

ifstream fin("patrate3.in");
ofstream fout("patrate3.out");

ll modul(ll k) {return (k<0?-k:k);}

struct pc{
    ll x, y;
    bool operator==(const pc &e) const
    {
        return (x==e.x&&y==e.y);
    }
    bool operator<(const pc &e) const
    {
        if(x!=e.x) return x<e.x;
        return y<e.y;
    }
    pc(){}
    pc(const ll _x, const ll _y)
    {
        x=_x;
        y=_y;
    }
};

class Hash{
public:
    Hash(){}
    bool find(const pc a)
    {
        int p=modul((100LL*a.x+a.y)%MOD);
        for(vector<pc>::iterator it=H[p].begin();it!=H[p].end();it++) if(*it==a) return true;
        return false;
    }
    void insert(const pc a)
    {
        int p=modul((100LL*a.x+a.y)%MOD);
        H[p].push_back(a);
    }
private:
    vector<pc> H[MOD];
};

pc a[N];
Hash H;

void Read(long long &x)
{
    int j, sgn;
    string cit;
    fin>>cit;
    if(cit[0]=='-')
    {
        sgn=-1;
        j=1;
    }
    else
    {
        sgn=1;
        j=0;
    }
    for(;j<cit.size();j++) if(cit[j]!='.') x=10*x+cit[j]-'0';
    x*=sgn*2;
}

int main()
{
    int n, i, j, sol=0;
    pc mij, x1, y1;
    fin>>n;
    for(i=1;i<=n;i++)
    {
        Read(a[i].x);
        Read(a[i].y);
        H.insert(a[i]);
    }
    for(i=1;i<=n;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            mij=pc((a[i].x+a[j].x)/2, (a[i].y+a[j].y)/2);
            x1=pc(mij.x-(a[i].y-mij.y), mij.y+(a[i].x-mij.x));
            y1=pc(mij.x-(a[j].y-mij.y), mij.y+(a[j].x-mij.x));
            if(H.find(x1)&&H.find(y1)) sol++;
        }
    }
    fout<<sol/2<<"\n";
}