Cod sursa(job #768409)

Utilizator SteveStefan Eniceicu Steve Data 16 iulie 2012 19:37:31
Problema Patrate 3 Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.23 kb
#include <fstream>
#include <vector>
#include <set>
#include <cmath>

using namespace std;

#define mod 1001

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

int N;
cutzu v[1005];
//vector <cutzu> h[1005];
set <pair <int, int> > H;

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

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

void Citire () {
    ifstream fin ("patrate3.in");
    fin >> N;
    char pars[100];
    char dummy[10];
    fin.getline (dummy, 7);
    int j;
    for (int i = 0; i < N; i++)
    {
        fin.getline (pars, 90);
        for (j = 0; pars[j] != '.'; j++)
            v[i].x = v[i].x * 10 + pars[j] - '0';
        j++;
        for (int k = j; k <= j + 3; k++)
            v[i].x = v[i].x * 10 + pars[k] - '0';
        for (j = j + 5; pars[j] != '.'; j++)
            v[i].y = v[i].y * 10 + pars[j] - '0';
        j++;
        for (int k = j; k <= j + 3; k++)
            v[i].y = v[i].y * 10 + pars[k] - '0';
        H.insert (make_pair (v[i].x, v[i].y));
    }
    fin.close ();
}

int Business () {
    int x3, y3, x2, y2, x1, y1;
    int xm, xf0, xf1, ym, yf0, yf1, xlol, ylol, x1p, y1p, xp, yp;
    int cnt = 0;
    cutzu u, t;
    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            if (v[i].y >= v[j].y) xlol = v[i].x, ylol = v[i].y, x1 = v[j].x, y1 = v[j].y;
			else xlol = v[j].x, ylol = v[j].y, x1 = v[i].x, y1 = v[i].y;

			yp = ylol - (xlol - x1);
			y1p = y1 - (xlol - x1);

			xp = xlol + (ylol - y1);
			x1p = x1 + (ylol - y1);
            u.x = xp;
            u.y = yp;
            t.x = x1p;
            t.y = y1p;
            if (H.find (make_pair (u.x, u.y)) != H.end () && H.find (make_pair (t.x, t.y)) != H.end ()) cnt++;
        }
    }
    return cnt >> 1;
}

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

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