Cod sursa(job #768396)

Utilizator SteveStefan Eniceicu Steve Data 16 iulie 2012 18:45:25
Problema Patrate 3 Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.67 kb
#include <fstream>
#include <vector>
#include <cmath>

using namespace std;

#define mod 1001
#define eps 0.00001
#define cf(a, b) (fabs (a - b) <= eps)

typedef struct {
    double x;
    double y;
} cutzu;

int N;
cutzu v[1005];
vector <cutzu> h[1005];

inline void Hashin (cutzu a) {
    int lol = ((int) a.x + (int) a.y) % mod;
    if (lol < 0) lol = -lol;
    h[lol].push_back (a);
}

inline int Hashout (cutzu a) {
    int n, lol = ((int) a.x + (int) a.y) % mod;
    if (lol < 0) lol = -lol;
    n = h[lol].size ();
    for (int i = 0; i < n; i++)
        if (fabs(h[lol][i].x - a.x) <= eps && fabs(h[lol][i].y - a.y) <= eps) return 1;
    return 0;
}

void Citire () {
    ifstream fin ("patrate3.in");
    fin >> N;
    for (int i = 0; i < N; i++)
    {
        fin >> v[i].x >> v[i].y;
        Hashin (v[i]);
    }
    //sort (v, v + N, cmp);
    fin.close ();
}

int Business () {
    double x3, y3, x2, y2;
    double xm, xf0, xf1, ym, yf0, yf1;
    int cnt = 0;
    cutzu u, t;
    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            x2 = v[j].x; y2 = v[j].y; x3 = v[i].x; y3 = v[i].y;
            xm = x2 + x3; ym = y2 + y3;
            xf1 = (xm + y3 - y2) / 2;
            xf0 = xm - xf1;
            yf1 = (ym + x2 - x3) / 2;
            yf0 = ym - yf1;
            u.x = xf0; u.y = yf0;
            t.x = xf1; t.y = yf1;
            if (Hashout (u) && Hashout (u)) cnt++;
        }
    }
    return cnt >> 1;
}

void Scriere () {
    ofstream fout ("patrate3.out");
    fout << Business ();
    fout.close ();
}

int main () {
    Citire ();
    Scriere ();
    return 0;
}