Cod sursa(job #3230795)

Utilizator Mihai_999Diaconeasa Mihai Mihai_999 Data 22 mai 2024 20:33:47
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <set>
#define nl '\n'

using namespace std;

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

const int NMAX = 1005;
const double EPS = 1e-5;

int n;

struct punct
{
    double x, 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;
    }
};
punct puncte[NMAX];
set<punct> set_puncte;

int main()
{
    int ans = 0;
    punct A, B, M, C, D;
    fin >> n;
    for (int i = 1; i <= n; i++)
    {
        fin >> puncte[i].x >> puncte[i].y;
        set_puncte.insert(puncte[i]);
    }
    sort(puncte+1, puncte+1+n);
    for (int i = 1; i <= n; i++)
    {
        for (int j = i+1; j <= n; j++)
        {
            A = puncte[i];
            B = puncte[j];
            M.x = (A.x+B.x)/2;
            M.y = (A.y+B.y)/2;
            double distX = M.x-A.x, distY = M.y-A.y;
            C.x = M.x-distY;
            C.y = M.y+distX;
            D.x = M.x+distY;
            D.y = M.y-distX;
            if (set_puncte.find(C) != set_puncte.end() && set_puncte.find(D) != set_puncte.end())
                ans++;
        }
    }
    fout << ans/2;
    return 0;
}