Pagini recente » Cod sursa (job #1288108) | Cod sursa (job #1574412) | Cod sursa (job #1576414) | Cod sursa (job #2496296) | Cod sursa (job #1319983)
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
const int mod = 666013;
const int NMax = 1002;
struct point{
int x,y;
}points[NMax];
vector<point> H[666013];
int hash_func(point X)
{
int x,y;
if(X.x < 0 )
x=-X.x;
else
x=X.x;
if(X.y < 0)
y=-X.y;
else
y=X.y;
return (x+y)%mod;
}
void Hash_Insert(point X)
{
int where = hash_func(X);
H[where].push_back(X);
}
int Hash_Find(point X)
{
int where = hash_func(X);
vector<point>::iterator it;
for(it = H[where].begin(); it != H[where].end(); it++ )
{
if(it->x == X.x && (it->y = X.y))
return 1;
}
return 0;
}
int getNumber(char c[])
{
int number=0;
int sign = 1;
int i = 0;
if(c[i]=='-')
{
sign = -1;
i++;
}
for(;c[i];i++)
{
if(c[i]>='0' && c[i] <='9')
{
number = number*10 + c[i]-'0';
}
}
number = number * sign;
}
int main()
{
int n,i,j;
freopen("patrate3.in","r",stdin);
freopen("patrate3.out","w",stdout);
scanf("%d\n",&n);
point newpoint;
char s[28];
for(i = 1;i <= n;i++)
{
scanf("%s",s);
newpoint.x=getNumber(s);
scanf("%s",s);
newpoint.y=getNumber(s);
//cout<<newpoint.x<<" "<<newpoint.y<<" "<<hash_func(newpoint)<<"\n";
Hash_Insert(newpoint);
points[i]=newpoint;
}
// //51.5700 10.9400
int sum = 0;
for(i=1;i<=n;i++)
{
int x1 = points[i].x;
int y1 = points[i].y;
for(j=i+1;j<=n;j++)
{
int x2 = points[j].x;
int y2 = points[j].y;
int mx = (x1 + x2) / 2;
int my = (y1 + y2) / 2;
int x3 = mx - (y1 - my);
int y3 = my + (x1 - mx);
int x4 = mx + (y1 - my);
int y4 = my - (x1 - mx);
point point1;
point point2;
point1.x = x3;
point1.y = y3;
point2.x = x4;
point2.y = y4;
if(Hash_Find(point1) && Hash_Find(point2))
{
//printf("%d %d %d %d \n", point1.x,point1.y,point2.x,point2.y);
sum++;
}
}
}
cout<<sum/2;
}