# [SMOJ1811]正方形个数

### 输入格式 1811.in

n=0$n=0$ 时，输入结束。

4
1 0
0 1
1 1
0 0
9
0 0
1 0
2 0
0 2
1 2
2 2
0 1
1 1
2 1
4
-2 5
3 7
0 0
5 2
0

### 输出样例 1811.out

1
6
1

AE=x2x1,BE=y2y1$\therefore AE=x_2-x_1, BE = y_2-y_1$
ABCD$\because □ABCD$ 为正方形
AB=BC,ABC=90°$\therefore AB = BC, ∠ABC=90°$
1+2=90°$\therefore ∠1+∠2=90°$
ABE,2+3=90°$\because 在△ABE中, ∠2+∠3=90°$
1=3$\therefore ∠1=∠3$
$\because$ABE$△ABE$BCF$△BCF$ 中，
E=F=90°,1=3,AB=BC$∠E=∠F=90°, ∠1=∠3, AB=BC$
ABEBCF$\because △ABE \cong △BCF$
AE=BF,BE=CF$\therefore AE = BF, BE = CF$
C(x2(y2y1),y2+(x2x1))$\therefore C(x_2-(y_2-y_1), y_2+(x_2-x_1))$

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

using namespace std;

const int maxn = 1e3 + 10;
const int prime = 30001;

struct Data { int x, y; bool bo; };

int n;
int x[maxn], y[maxn];
Data hash[prime];

void insert(int xx, int yy) {
int h = (xx * xx + yy * yy) % prime;
int p = h;
while ((hash[p].x != xx || hash[p].y != yy) && hash[p].bo) {
p += h % 107 + 1;
if (p >= prime) p -= prime;
}
hash[p].x = xx; hash[p].y = yy;
hash[p].bo = true;
}

bool find(int xx, int yy) {
int h = (xx * xx + yy * yy) % prime;
int p = h;
while ((hash[p].x != xx || hash[p].y != yy) && hash[p].bo) {
p += h % 107 + 1;
if (p >= prime) p -= prime;
}
return hash[p].bo;
}

int main(void) {
freopen("1811.in", "r", stdin);
freopen("1811.out", "w", stdout);
while (~scanf("%d", &n)) {
if (!n) break;
memset(hash, 0, sizeof hash);
for (int i = 0; i < n; i++) {
scanf("%d%d", &x[i], &y[i]);
insert(x[i], y[i]);
}

int ans = 0;
for (int i = 0; i + 1 < n; i++)
for (int j = i + 1; j < n; j++) {
int xc = x[i] - x[j], yc = y[i] - y[j];
if (find(x[i] - yc, y[i] + xc) && find(x[j] - yc, y[j] + xc)) ans++;
if (find(x[i] + yc, y[i] - xc) && find(x[j] + yc, y[j] - xc)) ans++;
}
printf("%d\n", ans >> 2);
}
return 0;
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120