Pagini recente » Cod sursa (job #891345) | Cod sursa (job #2058726) | Cod sursa (job #2327853) | Cod sursa (job #842691) | Cod sursa (job #533770)
Cod sursa(job #533770)
#include <fstream>
#include <vector>
#define nmax 20000
const double h1 = 1.58457398;
const double h2 = 0.317837245;
const double s = 0.866025404;
using namespace std;
ifstream in("triang.in");
ofstream out("triang.out");
vector< pair < double,double> >Hash[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=intreg(modul(x*h1+y*h2));
double x2,y2;
for(i=0;i<Hash[x1].size();i++)
{
x2 = Hash[x1][i].first;
y2 = Hash[x1][i].second;
if(modul(x-x2)<=0.001&&modul(y-y2)<=0.001)
return 1;
}
return 0;
}
int main()
{
int N,i,j,nr_tr=0;
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
//partea intreaga din x*h1 + y*h2
Hash[ intreg(modul(x*h1+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;
}