# poj2002~对哈希表的理解进一步加深了

Time比较长，1454MS，不过我不在乎了，毕竟我没那个实力去参加竞赛，自然也没必要纠结时间快慢，不超时，不报错就行，学会并熟练这个算法是最好的

x3=x1+y1-y2;
y3=y1+x2-x1;
x4=x2+y1-y2;
y4=y2+x2-x1;

`#include<iostream>  #include<string>  #include<cmath>  #define M 2005 using namespace std;  int n,px[M],py[M];struct point{int flag;int x;int y;struct point *next;};struct point *hash[M];void insert(struct point *h,int xx,int yy){if(h->flag==0){h->flag=1;h->x=xx;h->y=yy;h->next=new struct point;h->next->flag=0;}elseinsert(h->next,xx,yy);}int find(int xx,int yy){int key;key=abs((xx*xx+yy)%M);struct point *h=hash[key];while(1){if(h->flag==0)return 0;if(h->x==xx&&h->y==yy)return 1;else h=h->next;}}int main(){int i,j,xx,yy,key,ans,x1,y1,x2,y2,x3,y3,x4,y4;for(i=0;i<M;i++)hash[i]=new struct point;while(scanf("%d",&n),n!=0){for(i=0;i<M;i++)hash[i]->flag=0;for(i=0;i<n;i++){scanf("%d%d",&xx,&yy);px[i]=xx;py[i]=yy;key=abs((xx*xx+yy)%M);insert(hash[key],xx,yy);}ans=0;for(i=0;i<n;i++)for(j=0;j<n;j++)if(i!=j){x1=px[i];x2=px[j];y1=py[i];y2=py[j];if(!(x2>x1&&y2>=y1))continue;                    x3=x2+y2-y1;y3=y2-(x2-x1);x4=x1+y2-y1;y4=y1-(x2-x1);if(find(x3,y3)&&find(x4,y4))ans++;}printf("%d\n",ans);}return 0;}`

0 0