Cod sursa(job #1321964)

Utilizator priestnoobFMI - Dan Nema priestnoob Data 19 ianuarie 2015 18:20:19
Problema Patrate 3 Scor 100
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2014, Anul I Marime 1.07 kb
#include<fstream>
#include<algorithm>
#include<unordered_map>

using namespace std;

int n,nr;
long double aux;

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

struct duo
{
    long long  x, y;
}v[100001];

bool cmp(duo x, duo y)
{
    return (x.x < y.x  || (x.x == y.x  &&x.y < y.y ));
}

void citire()
{
    fin>>n;
    for(int i=0;i<n;++i)
    {
        fin>>aux;
        v[i].x=round(aux*10000);
        fin>>aux;
        v[i].y=round(aux*10000);
    }
}

void solve()
{
    sort(v,v+n,cmp);
    for(int i=0;i<n-2;++i)
    {
        for(int j=i+1;j<n;++j)
        {
            long long dx = abs(v[i].x - v[j].x);
            long long dy = abs(v[i].y - v[j].y);
            duo aux1,aux2;
            aux1.x = v[i].x + dy;
            aux1.y = v[i].y + dx;
            aux2.x = v[j].x + dy;
            aux2.y = v[j].y + dx;
            if (binary_search(v, v + n, aux1, cmp) && binary_search(v, v + n, aux2, cmp))
                nr++;
        }
    }
    fout<<nr;
}

int main()
{
    citire();
    solve();
}