poj2002 数正方形 hash
2012-03-04 10:38
204 查看
直接上渣代码了
#include <iostream> using namespace std; struct gtype { int x,y,next; }g[3000]; int first[1000100],tot,n,x[3010],y[3010],ans,h,tx,ty; int hash(int x,int y) { return (40000*x+y+800040000)%999991+1; } bool find(int x,int y) { int h = hash(x,y); bool f = false; for (int t=first[h];t!=-1;t=g[t].next) if (g[t].x==x && g[t].y==y) { f = true; break; } return f; } int main() { while (~scanf("%d",&n)) { tot = 0; memset(first,-1,sizeof(first)); for (int i=1;i<=n;i++) { scanf("%d%d",&x[i],&y[i]); h = hash(x[i],y[i]); tot++; g[tot].x = x[i]; g[tot].y = y[i]; g[tot].next = first[h]; first[h] = tot; } ans = 0; for (int i=1;i<=n;i++) for (int j=i+1;j<=n;j++) { if (i==j) continue; tx = x[i]-x[j]; ty = y[i]-y[j]; if (find(x[i]+ty,y[i]-tx) && find(x[j]+ty,y[j]-tx)) ans++; if (find(x[i]-ty,y[i]+tx) && find(x[j]-ty,y[j]+tx)) ans++; } printf("%d\n",ans/4); } return 0; }
相关文章推荐
- poj 2002(好题 链式hash+已知正方形两点求另外两点)
- poj 2002 hash(平面上若干点能够成多少正方形)
- poj 2002 HASH判断正方形
- 二分|hash(找正方形)poj2002
- Poj 2002 Squares (正方形个数 Hash)
- POJ 2002 Squares(计算几何 找正方形 hash枚举)
- poj 2002 :Squares(hash 不解释)
- POJ 2002 Squares(hash)
- POJ-2002-Squares(hash)
- POJ-2002 Squares Hash表+正方形顶点计算
- POJ 2002 Squares 求正方形的个数,点哈希
- POJ 2002 - Squares(hash)
- hash poj2002
- poj 2002 Squares (哈希+正方形已知相邻两点求另外两点的坐标)
- poj 2002 Squares(枚举+点hash)
- ACM: 几何题+hash题 poj 2002
- poj2002--Squares(n个点求正方形个数)
- POJ 2002 Squares (已知正方形对角线两点推另外两点,STL set)
- poj 2002 -- hash
- poj 2002 Squares 判断一些点能组成多少个正方形 二分查找