Cod sursa(job #1731320)

Utilizator GoogalAbabei Daniel Googal Data 18 iulie 2016 17:57:19
Problema Patrate 3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.61 kb
#include <fstream>
#include <vector>
#define pb psuh_back
#define mod 10111

using namespace std;

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

struct point_coord
{
    int x, y;
}w[1001];

int square_number, n;
double a, b;

vector<int> kush[mod];

point_coord rotation (point_coord A, point_coord B)
{
    A.x-=B.x;
    A.y-=B.y;

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

    A.x+=B.x;
    A.y+=B.y;

    return A;
}

inline bool find_value (point_coord A)
{
    int list=1LL*A.x*A.y%mod;
    if (list<0) list+=mod;

    for(int i=0; i<kush[list].size(); ++i)
    if (A.x==w[kush[list][i]].x && A.y==w[kush[list][i]].y) return 1;

    return 0;
}

void transform (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;

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

        transform(w[i].x);
        transform(w[i].y);

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

        kush[list].push_back(i);
    }

    for(int i=1; i<=n; ++i)
        for(int j=i+1; j<=n; ++j)
        {
            point_coord diag;

            diag.x=(w[i].x+w[j].x)/2;
            diag.y=(w[i].y+w[j].y)/2;

            point_coord A=rotation (w[i], diag);
            point_coord B=rotation (w[j], diag);

            if (find_value(A) && find_value(B)) ++square_number;
        }

    fout<<square_number/2;
}