poj2002 数正方形 hash
来源:互联网 发布:mac子弹头最火的色号 编辑:程序博客网 时间:2024/05/22 12:57
直接上渣代码了
#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;}
- poj2002 数正方形 hash
- 二分|hash(找正方形)poj2002
- poj2002 hash
- POJ2002 Squares(hash)
- poj2002 Squares(hash)
- poj2002--Squares(n个点求正方形个数)
- POJ2002---Squares(找正方形的个数)
- POJ2002-Squares-hash+枚举+几何
- POJ2002&&POJ3432 Squares(二分||hash)
- 数正方形
- poj2002——Squares(hash)
- POJ2002 正方形的个数(二维点的哈希)
- POJ2002
- poj2002
- poj2002
- poj2002
- POJ2002
- poj2002
- 利用JFreeChart进行图表开发
- 学会使用循环控制语句解决实际问题
- VIM常用快捷键
- android中service和aidl详细整理
- 学会用循环结构解决实际问题
- poj2002 数正方形 hash
- 深入理解Android消息处理系统——Looper、Handler、Thread
- 进制转换
- sprintf格式化输出
- Android Service 详解二:创建一个service
- 深入理解Lustre文件系统-第3篇 lustre lite
- JUnit4 学习总结
- 变长参数的使用
- 华为