Cod sursa(job #3262195)

Utilizator bogdan1479Luca Bogdan Alexandru bogdan1479 Data 9 decembrie 2024 09:41:02
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <fstream>
#include <set>

using namespace std;

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

const double EPS = 1e-5;

struct Punct
{
    double x, y;
    Punct(double x = 0.0, double y = 0.0): x(x), y(y) {}

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

int n;
Punct p[1001];
set<Punct> s;

void solutie()
{
    Punct m, a, b;
    int nrp = 0;
    for(int i = 1; i < n; ++i)
        for(int j = i + 1; j <= n; ++j)
        {
            m.x = (p[i].x + p[j].x) / 2;
            m.y = (p[i].y + p[j].y) / 2;
            a.x = m.x - p[j].y + m.y;
            a.y = m.y + p[j].x - m.x;
            b.x = m.x + p[j].y - m.y;
            b.y = m.y - p[j].x + m.x;
            if(s.find(a) != s.end() && s.find(b) != s.end()) ++nrp;
        }
    fout << nrp / 2;
}

int main()
{
    fin >> n;
    for(int i = 1; i <= n; ++i)
    {
        fin >> p[i].x >> p[i].y;
        s.insert(p[i]);
    }
    solutie();
    return 0;
}