poj 2002 Squares(hash)

来源:互联网 发布:网络创世纪uo 音乐 编辑:程序博客网 时间:2024/05/18 03:39

意义

给你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.
0 0