Pagini recente » Cod sursa (job #1046842) | Cod sursa (job #1078328) | Cod sursa (job #249256) | Cod sursa (job #670174) | Cod sursa (job #533753)
Cod sursa(job #533753)
#include <fstream>
#include <vector>
#define nmax 500
const double h1 = 0.038196601;
const double h2 = 0.036602540;
const double s = 0.866025404;
using namespace std;
ifstream in("triang.in");
ofstream out("triang.out");
vector< pair < double,double> >Hash[nmax][nmax];
struct p{double x,y;}V[nmax];
inline int intreg(double x){return x;}
inline double modul(double x){if(x<0)return -x;return x;}
inline int cauta(double x,double y)
{
int i,x1=modul(intreg(x*h1)),y1=modul(intreg(y*h2));
double x2,y2;
for(i=0;i<Hash[x1][y1].size();i++)
{
x2 = Hash[x1][y1][i].first;
y2 = Hash[x1][y1][i].second;
if(modul(x-x2)<0.0001&&modul(y-y2)<0.0001)
return 1;
}
return 0;
}
int main()
{
int N,i,j,nr_tr;
double x,y,x1,y1,x2,y2;
in>>N;
for(i=0;i<N;i++)
{
in>>x>>y;
V[i].x=x,V[i].y=y;
//inserez in hash in functie de x si y
Hash[ intreg(modul(x)*h1) ][intreg(modul(y)*h2) ].push_back(make_pair(x,y));
}
for(i=0;i<N;i++)
for(j=i+1;j<N;j++)
{
//calculez al treilea punct :
//c = -a*e - b*e^2
x1=V[i].x,y1=V[i].y,x2=V[j].x,y2=V[j].y;
x = (-x1-y1+x2+y2) /2;
y = (-x1 - y1 +x2+y2)*s;
//caut x y
if(cauta(x,y))
nr_tr++;
x = (-x2-y2+x1+y1) /2;
y = (-x2 - y2 +x1+y1)*s;
if(cauta(x,y))
nr_tr++;
}
out<<nr_tr;
return 0;
}