Cod sursa(job #2613086)

Utilizator Mihai_PredaPreda Mihai Dragos Mihai_Preda Data 9 mai 2020 14:40:27
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <iostream>
#include <fstream>
#include <set>
#include <cmath>

using namespace std;

const double eps = 1e-5;

struct punct
{
    double x, y;
    bool operator < (const punct& that) const {
	
		return (fabs(x - that.x) < eps ? y < that.y - eps : x < that.x - eps);
	
	}
};

int main()
{
    ifstream in("patrate3.in");
    int n;
    in >> n;
    set<punct> points;
    while(n--)
    {
        punct point;
        in >> point.x >> point.y;
        points.insert(point);
    }
    in.close();
    int rasp = 0;
    //patrat ABCD
    for(auto A = points.begin(); A != points.end(); A++)
        for(auto C = next(A); C != points.end(); C++)
        {
            if(A->x < C->x && A->y < C->y)
            {
                double midX = (A->x + C->x) / 2.0;
                double midY = (A->y + C->y) / 2.0;
                punct B, D; 
                B.x  = midX - C->y + midY;
                B.y = midY + C->x  - midX;
                D.x  = midX + C->y - midY;
                D.y = midY - C->x  + midX;
                if(points.find(B) != points.end() && points.find(D) != points.end())
                    rasp++;
            }

        }
    ofstream out("patrate3.out");
    out << rasp;
    out.close();
    return 0;
}