Cod sursa(job #3317093)

Utilizator mihaigeorgescuGeorgescu Mihai mihaigeorgescu Data 22 octombrie 2025 10:33:30
Problema Patrate 3 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.3 kb
#include <fstream>
#include <set>
#include <cmath>
#include <utility>
#include <iomanip>
#define pct pair<double,double>
#define x first
#define y second
using namespace std;
ifstream fcin("patrate3.in");
ofstream fout("patrate3.out");
int n,rez;
pct v[10001];
const double limit=0.001;
struct cmp
{
    bool operator()(const pct &a, const pct &b) const
    {
        if(abs(a.x-b.x)>limit) return a.x<b.x;
        if(abs(a.y-b.y)>limit) return a.y<b.y;
        return 0;
    }
};
int zero[2][2]=
{
    {0,0},
    {0,0}
};
int rot1[2][2]=
{
    {0,1},
    {-1,0}
};
int rot2[2][2]=
{
    {0,-1},
    {1, 0}
};
struct matrix
{
    int v[2][2];
    matrix(int a[2][2])
    {
        for(int i=0; i<2; i++)
            for(int j=0; j<2; j++)
                v[i][j]=a[i][j];
    }
    matrix operator*(const matrix &a) const
    {
        matrix rez(zero);
        for(int i=0; i<2; i++)
            for(int j=0; j<2; j++)
              for(int k=0; k<2; k++)
                 rez.v[i][j]=rez.v[i][j]+v[i][k]*a.v[k][j];
        return rez;
    }
};
set <pct, cmp> s;
inline pct rotdr(pct a, pct b)
{
    b.x-=a.x;
    b.y-=a.y;
    int mat[2][2]=
    {
        {b.x, 0},
        {b.y, 0}
    };
    matrix h(mat);
    matrix rr(rot1);
    h=rr*h;
    b.x=h.v[0][0];
    b.y=h.v[1][0];
    b.x+=a.x;
    b.y+=a.y;
    return b;
}
inline pct rotst(pct a, pct b)
{
    b.x-=a.x;
    b.y-=a.y;
    int mat[2][2]=
    {
        {b.x, 0},
        {b.y, 0}
    };
    matrix h(mat);
    matrix rr(rot2);
    h=rr*h;
    b.x=h.v[0][0];
    b.y=h.v[1][0];
    b.x+=a.x;
    b.y+=a.y;
    return b;
}
inline void print(pct a)
{
    fout<<fixed<<setprecision(4)<<a.x<<" "<<a.y<<'\n';
}
inline void verifst(int i, int j)
{
   pct c=rotst(v[i],v[j]);
   pct d=rotst(c,v[i]);
   if(s.count(c) && s.count(d))
      rez++;
}
inline void verifdr(int i, int j)
{
   pct c=rotdr(v[i],v[j]);
   pct d=rotdr(c,v[i]);
   if(s.count(c) && s.count(d))
    rez++;
}
signed main()
{
    fcin>>n;
    for(int i=1; i<=n; i++)
        fcin>>v[i].x>>v[i].y;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<i; j++)
        {
            verifst(i,j);
            verifdr(i,j);
        }
        s.insert(v[i]);
    }
    fout<<rez;
    return 0;
}