Pagini recente » Diferente pentru warm-up-2019/solutii/shoturi intre reviziile 75 si 74 | Istoria paginii runda/pregoni3/clasament | Istoria paginii runda/simulare_oji_10_2/clasament | Istoria paginii runda/shimudupaprega/clasament | Cod sursa (job #1008075)
#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();
}