Cod sursa(job #2757205)

Utilizator Robert.BrindeaBrindea Robert Robert.Brindea Data 4 iunie 2021 15:26:08
Problema Triang Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.52 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>

using namespace std;

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

const int MAXN = 1503;
const double precizie = 0.001, pi = 3.1415;


double modul(double x)
{
    if(x < 0) return -x;
    return x;
}

struct Punct
{
    double x, y;

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

    bool operator==(const Punct a)
    {
        return (modul(x - a.x) < precizie && modul(y - a.y) < precizie);
    }
    bool operator<(const Punct a)
    {
        if(modul(x - a.x) < precizie)
            return y < a.y;
        return x < a.x;
    }
};

Punct a[MAXN];
int n, res;

bool cauta(Punct x, int lo = 0, int hi = n)
{
    int mid = (lo+hi)/2;
    if(lo >= hi) return 0;
    if(a[mid] == x) return 1;
    else if(a[mid] < x) return cauta(x, mid+1, hi);
    else return cauta(x, lo, mid);
    return 0;
}

int main()
{
    fin >> n;
    for(int i = 0; i < n; i++)
        fin >> a[i].x >> a[i].y;
    sort(a, a+n);
    for(int i = 0; i < n; i++)
        for(int j = i+1; j < n; j++)
        {
            int x = a[j].x - a[i].x, y = a[j].y - a[i].y;
            Punct cautat = Punct(x*cos(pi/3) - y*sin(pi/3), x*sin(pi/3) + y*cos(pi/3));
            if(cauta(cautat))res++;

            cautat = Punct(x*cos(-pi/3) - y*sin(-pi/3), x*sin(-pi/3) + y*cos(-pi/3));
            if(cauta(cautat, j, n))res++;
        }
    fout << res;
    return 0;
}