Cod sursa(job #2773907)

Utilizator valentinchipuc123Valentin Chipuc valentinchipuc123 Data 9 septembrie 2021 11:32:43
Problema Triang Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <bits/stdc++.h>

using namespace std;

const double EPS=1e-5,
             c=0.5,
             s=sqrt(3)/2;

struct Punct
{
    double x,y;

    Punct(double xx=0.0,double yy=0.0)
    {
        x=xx, y=yy;
    }

    bool operator<(const Punct &A) const
    {
        if(abs(x - A.x) > EPS)
            return x < A.x;
        if(abs(y - A.y) > EPS)
            return y < A.y;
        return 0;
    }
};

set<Punct> S;

ifstream f("triang.in");
ofstream g("triang.out");

Punct rotire(const Punct &A,const Punct &B)
{
    double dx = B.x - A.x,
           dy = B.y - A.y;
    /**
    Punct C;
    C.x = dx * c - dy * s + A.x;
    C.y = dx * s + dy * c + A.y;
    */
    return Punct(dx * c - dy * s + A.x, dx * s + dy * c + A.y);
}

int main()
{
    int nrTr=0,N;
    Punct A,M;

    f>>N;
    while(N--)
    {
        f>>A.x>>A.y;
        for(auto &B : S)
        {
            M=rotire(A, B);
            if(S.find(M) != S.end())
                nrTr++;
        }
        S.insert(A);
    }
    g<<nrTr;
    return 0;
}