Cod sursa(job #1198412)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 15 iunie 2014 16:46:47
Problema Patrate 3 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.18 kb
#include <iostream>
#include <fstream>
#include <set>
#include <algorithm>

using namespace std;

const int Nmax = 1000 + 2;
const double EPS = 1e-6;

class Point
{
public:

    double x, y;

    Point( const double _x = 0, const double _y = 0 )
    {
        x = _x;
        y = _y;
    }

    bool operator < ( const Point &P ) const
    {
        if ( abs( x - P.x ) <= EPS )
                return y < P.y;
        else
                return x < P.x;
    }
};

int N;
Point P[Nmax];
set <Point> US;

int main()
{
    ifstream in("patrate3.in");
    ofstream out("patrate3.out");

    in >> N;

    for ( int i = 1; i <= N; ++i )
    {
        in >> P[i].x >> P[i].y;

        US.insert( P[i] );
    }

    sort( P + 1, P + N + 1 );

    int sol = 0;

    for ( int i = 1; i < N; ++i )
    {
        for ( int j = i + 1; j <= N; ++j )
        {
            Point A, B;

            A.x = P[i].x + P[i].y - P[j].y;
            A.y = P[i].y + P[j].x - P[i].x;
            B.x = P[j].x + P[i].y - P[j].y;
            B.y = P[j].y + P[j].x - P[i].x;

            if ( US.find( A ) != US.end() && US.find( B ) != US.end() )
                    sol++;
        }
    }

    out << sol << "\n";

    return 0;
}