POJ 2002 hash+枚举
来源:互联网 发布:指纹识别芯片 算法 编辑:程序博客网 时间:2024/06/04 19:40
题意:给出n个点,问组成了多少个正方形。
枚举两个点,求出另两个点然后hash看是否存在。不会hash,基本上是搬了黄大神的代码= =吗。
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int mm=1005;const int mod=100007;struct point{ int x,y;};struct hashtable{ int h[mod],p[mod],size; point s[mod]; int hash(int x,int y) { return ((x*131+y+mod)&0x7FFFFFFF)%mod; } void insert(int x,int y) { int i,id=hash(x,y); for(i=h[id]; i>=0; i=p[i]) if(s[i].x==x&&s[i].y==y)return; s[size].x=x,s[size].y=y; p[size]=h[id],h[id]=size++; } int find(int x,int y) { int i,id=hash(x,y); for(i=h[id]; i>0; i=p[i]) if(s[i].x==x&&s[i].y==y)return i; return 0; } void clear() { size=1; memset(h,-1,sizeof(h)); }} ht;bool check(point P,point Q){ int add1=P.y-Q.y,add2=Q.x-P.x; return ht.find(P.x+add1,P.y+add2)&&ht.find(Q.x+add1,Q.y+add2);}int main(){ int n; point data[1005]; while(~scanf("%d",&n),n) { ht.clear(); for(int i=0; i<n; i++) scanf("%d%d",&data[i].x,&data[i].y),ht.insert(data[i].x,data[i].y); int ans=0; for(int i=0; i<n; i++) for(int j=0; j<n; j++) if(j!=i&&check(data[i],data[j])) ans++; printf("%d\n",ans/4); } return 0;}
- POJ 2002 hash+枚举
- poj 2002 Squares(枚举+点hash)
- poj 1054 枚举+hash
- POJ 2002 hash(枚举+哈希) 或者 枚举+二分
- POJ 1840 Eqs(枚举+HASH)
- [POJ 1840]Eqs[hash][枚举]
- POJ 2002 Squares(计算几何 找正方形 hash枚举)
- POJ 1971 Parallelogram Counting(枚举+HASH)
- POJ 1840 Eqs 折半枚举、hash
- poj 1840 Eqs(暴力枚举+hash)
- POJ 2002 hash 题目
- POJ 2002 (hash)
- poj 2002 -- hash
- POJ 2002 (hash + 几何)
- POJ 2002 Squares Hash
- POJ 2002 Squares -- Hash
- poj 2002 Squares,hash
- POJ 2002 Squares (Hash)
- Quartz事物调度
- Android bootchart使用步骤
- Ubuntu下轻松建立你的内核驱动开发环境
- linux内核源码目录结构
- Turbo码 - 接近完美的编码
- POJ 2002 hash+枚举
- 用Eclipse+Cygwin+CDT+NDK来创建一个简单的Android JNI 项目
- 数据库索引的作用和优点缺点
- 关于resultset的小结
- Android Notification 使用详解之一:基础应用
- erro while loading shared libraries: libqpe.so.1: cannot open shared object file: No such file or di
- google protocol buffer协议的socket通信实例
- 清空GridView数据行
- 【病毒相关】