#include <iostream> #include <cmath> #include <map> using namespace std; const int prime=1999; struct point{ int x,y; }p[1001]; struct hashtable{ int value; map<int,int> mymap; }myhash[prime]; void setHash(int x,int y){ int h= (x*x+y*y) % prime; myhash[h].value=1; myhash[h].mymap.insert(pair<int, int>(x, y)); } bool Search(int x,int y) { map<int,int>::iterator ptr; int h = (x*x+y*y) % prime; if(myhash[h].value!=1)return false; ptr=myhash[h].mymap.find(x); int tt=(*ptr).second; if(tt==y)return true; return false; } int work(int n){ int i,j; int sum=0; for(i=1;i<n;i++) for(j=i+1;j<=n;j++) { int x1 = p[i].x - (p[i].y - p[j].y); int y1 = p[i].y + (p[i].x - p[j].x); int x2 = p[j].x - (p[i].y - p[j].y); int y2 = p[j].y + (p[i].x - p[j].x); if(Search(x1,y1) && Search(x2,y2)) sum++; } for(i=1;i<n;i++) for(j=i+1;j<=n;j++){ int x3 = p[i].x + (p[i].y - p[j].y); int y3 = p[i].y - (p[i].x - p[j].x); int x4 = p[j].x + (p[i].y - p[j].y); int y4 = p[j].y - (p[i].x - p[j].x); if(Search(x3,y3) && Search(x3,y3)) sum++; } return sum/4; } int main(){ int n; while(1){ cin>>n; if(n==0)break; for(int j=0;j<prime;j++){ myhash[j].value=-1; } for(int i=1;i<=n;i++){ cin>>p[i].x>>p[i].y; setHash(p[i].x,p[i].y); } cout<<work(n)<<endl; } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
today lazy . tomorrow die .