Cod sursa(job #2654558)

Utilizator SergiuS3003Sergiu Stancu Nicolae SergiuS3003 Data 1 octombrie 2020 16:30:32
Problema Triang Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <fstream>
#include <cmath>
#include <set>

using namespace std;
const double EPS = 1e-5;

struct Punct
{
    double x, y;

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

    bool operator < ( const Punct& A ) const
    {
        if ( abs ( x - A.x ) <= EPS )
            return y + EPS  <= A.y;

        return x + EPS <= A.x;
    }

    bool operator > ( const Punct& A ) const
    {
        return A < *this ;
    }
};

int N;

set<Punct> S;

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

Punct rotire ( const Punct &A, const Punct &B )
{
    static double c = 0.5, s = sqrt ( 3 ) / 2;
    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 C;
}

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

    for ( i = 1; i <= N; i++ )
    {
        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;
}