Cod sursa(job #2957364)

Utilizator IvanAndreiIvan Andrei IvanAndrei Data 22 decembrie 2022 14:42:17
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <fstream>
#include <set>
#include <cmath>

using namespace std;

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

#define pii pair <int, int>

const int max_size = 1e3 + 1;

pii a[max_size];
set <pii> s;

int main ()
{
    int n;
    in >> n;
    for (int i = 1; i <= n; i++)
    {
        double x, y;
        int xx, yy;
        in >> x >> y;
        x = round(x * 10000);
        y = round(y * 10000);
        xx = x;
        yy = y;
        a[i] = {xx, yy};
        s.insert(a[i]);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (i == j)
                continue;
            int x1 = a[i].first, y1 = a[i].second, x2 = a[j].first, y2 = a[j].second;
            int dx = x2 - x1, dy = y1 - y2;
            pii aux1 = {x1 + dy, y1 + dx}, aux2 = {x2 + dy, y2 + dx};
            if (s.find(aux1) != s.end() && s.find(aux2) != s.end())
            {
                ans++;
            }
        }
    }
    out << ans / 4;
    in.close();
    out.close();
    return 0;
}