Cod sursa(job #2658301)

Utilizator AndreiAlexandru2k3Ciucan Andrei Alexandru AndreiAlexandru2k3 Data 13 octombrie 2020 17:39:33
Problema Triang Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.15 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;
}