Cod sursa(job #2619488)

Utilizator usureluflorianUsurelu Florian-Robert usureluflorian Data 27 mai 2020 19:44:24
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <bits/stdc++.h>

#define x first
#define y second

using namespace std;

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

const double eps=0.0001;
const int nmax = 1e3 + 3;

int n, ans;

pair <double, double> v[nmax], a, b;

bool cmp(pair <double, double> a, pair <double, double> b)
{
    return (a.x <= b.x - eps || a.x < b.x + eps && a.y <= b.y - eps);
}

int main()
{
    f >> n;
    for(int i = 1; i <= n; ++i) f >> v[i].x >> v[i].y;

    sort(v + 1, v + n + 1);

    for(int i = 1; i <= n; ++i)
    {
        for(int j = i + 1; j <= n; ++j)
        {
            if(v[j].x > v[i].x && v[j].y >= v[i].y)
            {
                double dx = v[j].x - v[i].x;
                double dy = v[j].y - v[i].y;

                a = make_pair(v[i].x - dy, v[i].y + dx);
                b = make_pair(v[j].x - dy, v[j].y + dx);

                ans += (binary_search(v + 1,v + n + 1, b, cmp) && binary_search(v + 1,v + n + 1, a, cmp));
            }
        }
    }

    g << ans;

    return 0;
}