Cod sursa(job #768050)

Utilizator SteveStefan Eniceicu Steve Data 15 iulie 2012 20:26:52
Problema Patrate 3 Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.15 kb
#include <fstream>
#include <map>
#include <cmath>
#include <iostream>

using namespace std;

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

int N;
cutzu v[1005];
struct lolcomp {
    bool operator () (const cutzu a, const cutzu b) const
    {
        if (a.x == b.x) return a.y < b.y;
        return a.x < b.x;
    }
};

map <cutzu, int, lolcomp> mp;

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

int Business () {
    float mijx, mijy, dx, dy, x3, y3, x2, y2;
    float dist, p2, a, b, xp, yp;
    cutzu u, t;
    int cnt = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            dist = sqrt ((v[i].x - v[j].x) * (v[i].x - v[j].x) + (v[i].y - v[j].y) * (v[i].y - v[j].y));
            p2 = (v[i].x - v[j].x) / (v[j].y - v[i].y);
            dist /= 2;
            b = dist / (sqrt (p2 * p2 + 1));
            a = b * p2;
            xp = (v[i].x + v[j].x) / 2;
            yp = (v[i].y + v[j].y) / 2;
            u.x = b + xp;
            u.y = a + yp;
            if (mp[u]) cnt++;// cout << u.x << " " << u.y << "\n";
            /*mijx = (v[i].x + v[j].x) / 2;
            mijy = (v[i].y + v[j].y) / 2;
            dx = abs (mijx - v[i].x);
            dy = abs (mijy - v[i].y);
            if (v[i].y < v[j].y)
            {
                x2 = mijx + dy;
                y2 = mijy - dx;
                x3 = mijx - dy;
                y3 = mijy + dx;
            }
            else
            {
                x2 = mijx - dy;
                y2 = mijy - dx;
                x3 = mijx + dy;
                y3 = mijy + dx;
            }
            u.x = x2;
            u.y = y2;
            t.x = x3;
            t.y = y3;
            if (mp[u] && mp[t]) cnt++;*/
            //cout << x2 << " " << y2 << "\n";
        }
    }
    return cnt;
}

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

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