Cod sursa(job #3266230)

Utilizator bogdan1479Luca Bogdan Alexandru bogdan1479 Data 6 ianuarie 2025 17:53:01
Problema Triang Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.34 kb
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <cmath>

using namespace std;

const int NMAX = 1501;

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

struct pct
{
    double x, y;
} p[NMAX];

int n;
long long sol;
unordered_map<double, unordered_set<double>> m;

void rotunjire(pct& a)
{
    a.x = (int)(a.x * 1000.0) / 1000.0;
    a.y = (int)(a.y * 1000.0) / 1000.0;
}

double dis(const pct& a, const pct& b)
{
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

int main()
{
    pct crt, crt2;
    fin >> n;
    for(int i = 1; i <= n; ++i)
    {
        fin >> p[i].x >> p[i].y;
        rotunjire(p[i]);
        m[p[i].x].insert(p[i].y);
    }
    for(int i = 1; i < n; ++i)
        for(int j = i + 1; j <= n; ++j)
        {
            crt = {(p[i].x + p[j].x) / 2, (p[i].y + p[j].y) / 2}, crt2 = crt;
            double l = dis(p[i], p[j]), dx = (p[j].y - p[i].y) / l, dy = (p[i].x - p[j].x) / l, coef = (sqrt(3) / 2) * l;
            crt.x += dx * coef, crt.y += dy * coef;
            crt2.x -= dx * coef, crt2.y -= dy * coef;
            rotunjire(crt), rotunjire(crt2);
            if(m[crt.x].find(crt.y) != m[crt.x].end()) ++sol;
            if(m[crt2.x].find(crt2.y) != m[crt2.x].end()) ++sol;
        }
    fout << sol / 2;
    return 0;
}