Cod sursa(job #3309404)

Utilizator raulthestormIlie Raul Ionut raulthestorm Data 4 septembrie 2025 13:35:10
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.16 kb
#include <fstream>
#include <cmath>
#include <set>

using namespace std;
const double EPS = 1e-5;
const int NMAX = 1001;

int n, cnt;
struct punct
{
    double x, y;
    bool operator<(const punct &B)const
    {
        if(abs(x - B.x) > EPS)
            return x < B.x;
        //
        if(abs(y - B.y) > EPS)
            return y < B.y;
        return 0;
    }
} pc[NMAX];

set<punct> S;

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

int main()
{
    int i, j;
    f >> n;
    for(i = 1; i <= n; i++)
        f >> pc[i].x >> pc[i].y, S.insert(pc[i]);
    //
    punct mij, c, d;
    for(i = 1; i < n; i++)
        for(j = i + 1; j <= n; j++)
        {
            mij.x = (pc[i].x + pc[j].x) / 2;
            mij.y = (pc[i].y + pc[j].y) / 2;
            //
            c.x = mij.x - pc[j].y + mij.y;
            c.y = mij.y + pc[j].x - mij.x ;
            //
            d.x = mij.x + pc[j].y - mij.y;
            d.y = mij.y - pc[j].x + mij.x;
            //
            if(S.find(c) != S.end() && S.find(d) != S.end())
                cnt++;
        }
    g << cnt / 2;
    f.close();
    g.close();
    return 0;
}