Cod sursa(job #3235309)

Utilizator alexvali23alexandru alexvali23 Data 16 iunie 2024 21:24:47
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <iostream>
#include <fstream>
#include <set>
#include <math.h>
using namespace std;
ifstream f ("patrate3.in");
ofstream g ("patrate3.out");
const int eps = 10000;

struct Point
{
    int x, y;
    bool operator <(const Point& a) const
    {
        if(x != a.x)
            return x < a.x;
        if(x != a.y)
            return y < a.y;
        return 0;
    }
};

int aprox(float x)
{
    return round(x * eps);
}
set<Point> Points;

int main()
{
    int n, cont = 0;
    float x,y;
    f >> n;
    for(int i = 0; i < n; i++)
    {
        f >> x >> y;
        Points.insert({aprox(x), aprox(y)});
    }
    for(Point i : Points)
        for(Point j : Points)
            if(i.x != j.x && i.y != j.y)
            {
                int cx = i.y - j.y;
                int cy = j.x - i.x;
                if(Points.find({i.x + cx, i.y + cy}) != Points.end() && Points.find({j.x + cx, j.y + cy}) != Points.end())
                    cont ++;
            }
    g << cont / 4;

    return 0;
}