意义
给你n个点的坐标,问你可以围成多少个正方形。
思路
可以得出
temp.x = p[i].x + (p[i].y - p[j].y);
temp.y = p[i].y + (p[j].x - p[i].x);
和
temp.x = p[j].x + (p[i].y - p[j].y);
temp.y = p[j].y + (p[j].x - p[i].x);
然后就可以枚举两个点了,搞搞就好了。
const
maxn=999987;
var
x,y,hash:array [1..maxn] of longint;
ans,i,j,n:longint;
procedure insertion(x,y:longint);
var
i:longint;
k:int64;
begin
k:=x*50000+y;
i:=abs(k) mod maxn;
while (hash[i]<>-5201314) and (hash[i]<>k) do i:=i mod maxn+1;
hash[i]:=k;
end;
function find(x,y:longint):boolean;
var
i:longint;
k:int64;
begin
k:=x*50000+y;
i:=abs(k) mod maxn;
while (hash[i]<>-5201314) and (hash[i]<>k) do i:=i mod maxn+1;
if hash[i]=k then exit(true)
else exit(false);
end;
begin
readln(n);
while n<>0 do
begin
for i:=0 to maxn do
hash[i]:=-5201314;
ans:=0;
for i:=1 to n do
begin
readln(x[i],y[i]);
insertion(x[i],y[i]);
end;
for i:=1 to n do
for j:=i+1 to n do
if (find((y[i]-y[j])+x[i],((x[j]-x[i])+y[i])))
and (find((y[i]-y[j])+x[j],(x[j]-x[i])+y[j])) then inc(ans);
writeln(ans div 2);
readln(n);
end;
end.