Pagini recente » Cod sursa (job #2278981) | Cod sursa (job #1513412) | Cod sursa (job #2274585) | Cod sursa (job #2421117) | Cod sursa (job #533799)
Cod sursa(job #533799)
#include <fstream>
#include <vector>
#define nmax 100000
const double h1 = 1.58457398;
const double h2 = 2.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;}
int N;
inline int cauta(double x,double y)
{
int i;
double x2,y2;
for(i=0;i<N;i++)
{
x2=V[i].x;
y2=V[i].y;
if(modul(x-x2)<=0.001&&modul(y-y2)<=0.001)
{
return 1;
}
}
/*int i,x1=intreg(modul(x*h1+y*h2));
x1=x1%100000;
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 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))%100000 ].push_back(make_pair(x,y));
}
for(i=0;i<N;i++)
for(j=0;j<N;j++)
{
if(j==i)continue;
//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++;
}
out<<nr_tr;
return 0;
}