Cod sursa(job #1008075)

Utilizator grgcucu4e5hrbedrbsadvas grgcucu Data 10 octombrie 2013 10:13:13
Problema Triang Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.45 kb
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

struct punct{
    float x, y;
};

struct segment{
    float l;

    bool operator <(const segment& b) const
    {
        return l < b.l;
    }
};

void af(int rez);
void cit();
void detDist();
int detTriunghiuri();

vector<punct> pct;
vector<segment> segs;

int main()
{
    cit();
    detDist();
    int rez = detTriunghiuri();
    af(rez);
    return 0;
}

int detTriunghiuri()
{
    int nr = 0, nrsegm = 0;

    for(int i=1; i<segs.size(); i++)
    {
        //static int nrsegm = 1;

        if(segs[i-1].l == segs[i].l)
            nrsegm++;
        else
        {
            nr = nr + nrsegm/2;
            nrsegm = 0;
        }
    }

    nr = nr + nrsegm/2;

    return nr;
}

void detDist()
{
    //(n(n+1))/2
    for(int i=0; i<pct.size(); i++)
        for(int j=i+1; j<pct.size(); j++)
        {
            segment tS;
            float xs = pct[i].x-pct[j].x, ys = pct[i].y - pct[j].y;
            tS.l = sqrt(xs * xs + ys * ys);

            segs.push_back(tS);
        }

    sort(segs.begin(), segs.end());
}

void cit()
{
    ifstream fin("triang.in");

    int n;
    fin>>n;

    for(int i=0; i<n; i++)
    {
        punct tP;
        fin>>tP.x>>tP.y;
        pct.push_back(tP);
    }
}

void af(int rez)
{
    ofstream fout("triang.out");
    fout<<rez;
    fout.close();
}