Pagini recente » Profil M@2Te4i | Rating Ardelean Antonio (ToNNy) | Cod sursa (job #246945) | Cod sursa (job #117718) | Cod sursa (job #1554498)
#include<iostream>
#include<fstream>
#include<vector>
#include<cmath>
#define P 123457
#define Q 1001
#define nmax 1009
using namespace std;
ifstream fin ("patrate3.in");
ofstream fout ("patrate3.out");
struct coord{
long long int x, y;
};
int n, cnt;
vector <coord> L[P];
coord a[nmax];
void Citire()
{
int i, j;
long long int nr1, nr2, R;
float x, y;
coord q;
fin >> n;
for (i=1; i<=n; i++)
{
fin >> x >> y;
nr1 = 1LL * x * 10000; nr2 = 1LL * y * 10000;
a[i].x = nr1; a[i].y = nr2;
R = (nr1*Q + nr2) % P;
q.x = nr1; q.y = nr2;
L[R].push_back(q);
}
}
void Cauta(long long int x2, long long int y2, long long int x3, long long int y3)
{
int found1, found2, j;
long long int R;
found1 = found2 = 0;
R = (x2*Q + y2) % P;
for (j=0; j<L[R].size() && !found1; j++)
if (L[R][j].x == x2 && L[R][j].y == y2)
found1 = 1;
if (!found1) return;
R = (x2*Q + y2) % P;
for (j=0; j<L[R].size() && !found2; j++)
if (L[R][j].x == x3 && L[R][j].y == y3)
found2 = 1;
if (found1 == 1 && found2 == 1) cnt++;
}
void Verifica(long long int x0, long long int y0, long long int x1, long long int y1)
{
int i, j;
long long int dx, dy, x2, y2, x3, y3;
dx = x1 - x0;
dy = y1 - y0;
x2 = x1 + dy;
y2 = y1 - dx;
x3 = x0 + dy;
y3 = y0 - dx;
Cauta(x2, y2, x3, y3);
x2 = x1 - dy;
y2 = y1 + dx;
x3 = x0 - dy;
y3 = y0 + dx;
Cauta(x2, y2, x3, y3);
}
void Rezolva()
{
int i, j;
long long int x0, y0, x1, y1;
for (i=1; i<=n; i++)
{
for (j=i+1; j<=n; j++)
{
x0 = a[i].x; y0 = a[i].y;
x1 = a[j].x; y1 = a[i].y;
Verifica(x0, y0, x1, y1);
}
}
fout << cnt << "\n";
}
int main ()
{
Citire();
Rezolva();
fin.close();
fout.close();
return 0;
}