poj 2002 Squares(hash)

意义

给你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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值