Cod sursa(job #461815)

Utilizator SpiderManSimoiu Robert SpiderMan Data 8 iunie 2010 17:45:46
Problema Patrate 3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.86 kb
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;

const char FIN[] = "patrate3.in", FOU[] = "patrate3.out";
const int MAX_N = 1005;
const double EPS = 0.0001;


struct vect
{
    double abs, ord;
} ;

inline bool operator < (const vect &a, const vect &b)
{
    if ( fabs ( a.abs - b.abs ) <= EPS ) return a.ord - b.ord < -EPS;
    return a.abs - b.abs < -EPS;

}

inline bool operator == (const vect &a, const vect &b)
{
    if ( a.abs == b.abs ) return a.ord < b.ord;
    return a.abs < b.abs;
}

vect V[MAX_N];
int N, sol;


void solve ()
{
    for (int i = 1; i < N; ++i)
        for (int j = i + 1; j <= N; ++j)
        {
            vect point_a, point_b, point;

            point.abs = ( V[i].abs + V[j].abs ) / 2;
            point.ord = ( V[i].ord + V[j].ord ) / 2;

            double direction_a = fabs ( point.abs - V[i].abs ) ;
            double direction_b = fabs ( point.ord - V[i].ord ) ;

            bool verf = V[i].ord + EPS < V[j].ord;

            verf ? point_a.abs = point.abs + direction_b : point_a.abs = point.abs - direction_b ;
            verf ? point_a.ord = point.ord - direction_a : point_a.ord = point.ord - direction_a ;
            verf ? point_b.abs = point.abs - direction_b : point_b.abs = point.abs + direction_b ;
            verf ? point_b.ord = point.ord + direction_a : point_b.ord = point.ord + direction_a ;

            if ( binary_search ( V + 1, V + N + 1, point_a ) )
                if ( binary_search ( V + 1, V + N + 1, point_b ) )
                    ++sol;
        }

    printf("%d", sol >> 1);
}

int main ()
{
    freopen ( FIN, "r", stdin );
    freopen ( FOU, "w", stdout );

    scanf("%d", &N);

    for (int i = 1; i <= N; ++i)
        scanf("%lf %lf", &V[i].abs, &V[i].ord);

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

    solve ();

    return 0;
}