Cod sursa(job #1302980)

Utilizator Impaler_009Mihai Nitu Impaler_009 Data 27 decembrie 2014 15:11:54
Problema Patrate 3 Scor 100
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2014, Anul I Marime 1.57 kb
#include <fstream>
#include <vector>

#define mod 10111

using namespace std;

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

struct point
{
    int x,y;
}v[1001];

int cnt,n;
double a,b;

vector<int> H[mod];

point rotation (point A, point by)
{
    A.x -= by.x;
    A.y -= by.y;

    swap (A.x,A.y);
    A.x = - A.x;

    A.x += by.x;
    A.y += by.y;

    return A;
}

bool hash_find (point A)
{
    int h = 1LL*A.x*A.y%mod;
    if (h < 0)
        h += mod;

    for (int i = 0; i<H[h].size(); ++i)
    {
        if (A.x == v[H[h][i]].x && A.y == v[H[h][i]].y)
            return 1;
    }

    return 0;
}

void adjust (int &x)
{
    if (x >= 0)
    {
        if (x%10 == 9)
            x = x/10 + 1;
        else x = x/10;
    }
    else
    {
        if (-x%10 == 9)
            x = x/10-1;
        else x = x/10;
    }
}

int main()
{
    fin>>n;

    for (int i=1; i<=n; ++i)
    {
        fin>>a>>b;
        a *= 100000;
        b *= 100000;

        v[i].x = a;
        v[i].y = b;

        adjust (v[i].x);
        adjust (v[i].y);

        int h = 1LL*v[i].x*v[i].y%mod;
        if (h < 0)
            h += mod;

        H[h].push_back (i);
    }

    for (int i=1; i<=n; ++i)
        for (int j=i+1; j<=n; ++j)
    {
        point Med;

        Med.x = (v[i].x + v[j].x)/2;
        Med.y = (v[i].y + v[j].y)/2;

        point A = rotation (v[i],Med);
        point B = rotation (v[j],Med);

        if (hash_find (A) && hash_find(B))
            ++cnt;
    }

    fout<<cnt/2;
}