Cod sursa(job #3309225)

Utilizator StefanRaresStefan Rares StefanRares Data 2 septembrie 2025 17:44:31
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <iostream>
#include <fstream>
#include <cmath>
#include <set>
using namespace std;
ifstream f("patrate3.in");
ofstream g("patrate3.out");
const double EPS = 1e-5;
struct punct
{
    double x, y;
}v[1001];
struct comp
{
    bool operator()(const punct &a, const punct &b) const
    {
        if(abs(a.x - b.x) > EPS) return a.x < b.x;
        if(abs(a.y - b.y) > EPS) return a.y < b.y;
        return 0;
    }
};
set<punct, comp> s;
int main()
{
    int n, i, j, cnt = 0;
    punct mij, d1, d2;
    f >> n;
    for(i = 1; i <= n; i++)
    {
        f >> v[i].x >> v[i].y;
        s.insert(v[i]);
    }
    for(i = 1; i <= n; i++)
        for(j = i + 1; j <= n; j++)
        {
            mij.x = (v[i].x + v[j].x) / 2, mij.y = (v[i].y + v[j].y) / 2;
            d1.x = mij.y - v[j].y + mij.x, d1.y = v[j].x - mij.x + mij.y;
            d2.x = v[j].y - mij.y + mij.x, d2.y = mij.x - v[j].x + mij.y;
            if(s.find(d1) != s.end() && s.find(d2) != s.end())
                cnt ++;
        }
    g << cnt / 2;
    f.close();
    g.close();
    return 0;
}