Cod sursa(job #3377697)

Utilizator BidonTurtitBezdedan Eric BidonTurtit Data 24 noiembrie 2026 01:57:33
Problema Triang Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.34 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#define eps 1e-3
using namespace std;

ifstream fin("triang.in");
ofstream fout("triang.out");
int n, nr = 0;

struct punct
{
    double x, y;
} p[1505];

bool cmp(punct a, punct b)
{
    if (a.x == b.x)
        return a.y < b.y;
    else
        return a.x < b.x;
}

int cautare_binara(punct c)
{
    int i, step;
    for (step = 1; step <= n / 2; step <<= 1)
        ;
    for (i = 1; step; step >>= 1)
    {
        if (i + step <= n && cmp(c, p[i + step]) == 1)
            i += step;
    }
    if (abs(c.x - p[i].x) < eps && abs(c.y - p[i].y) < eps)
        return 1;
    else
        return 0;
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> p[i].x >> p[i].y;
    }
    sort(p + 1, p + n + 1, cmp);
    for (int i = 1; i < n; i++)
    {
        for (int j = i + 1; j <= n; j++)
        {
            double dx = p[j].x - p[i].x;
            double dy = p[j].y - p[i].y;

            double mx = (p[i].x + p[j].x) / 2;
            double my = (p[i].y + p[j].y) / 2;

            double h = sqrt(3.0) / 2;

            punct c1, c2;

            c1.x = mx - dy * h;
            c1.y = my + dx * h;

            c2.x = mx + dy * h;
            c2.y = my - dx * h;
            nr = nr + cautare_binara(c1) + cautare_binara(c2);
        }
    }
    cout << nr;
    return 0;
}