poj 2002 hash(平面上若干点能够成多少正方形)
来源:互联网 发布:天天向上网络版权费 编辑:程序博客网 时间:2024/06/06 02:49
题意:给定二维平面上不超过1000个点(点坐标的绝对值<=20000),问这些点能够构成多少个正方形。
思路:枚举两个顶点,可以确定另外两个顶点的位置,判断另外两个顶点是否存在于点集中。先用hash把点存储一下,然后判断。此处用了stl 的set。
因为多组,所以一开始要清空set,忘了这一步导致wa了多次。
#include <cstdio>#include <cstring>#include <algorithm>#include <set>using namespace std;int n;struct node{ int x,y;};node p[1005];set<int> h;int id(int x,int y){ return x*40001+y;}int main(){ while(scanf("%d",&n) && n){ int res=0; h.clear(); for(int i = 0;i<n;i++){ scanf("%d %d",&p[i].x,&p[i].y); h.insert(id(p[i].x,p[i].y)); } for(int i = 0;i<n;i++){ //for(int j = i+1;j<n;j++){//这么枚举会出错,看了discuss知道的 for(int j = 0;j<n;j++){ if(i==j) continue; int x1 = p[i].x+(p[i].y-p[j].y); int y1 = p[i].y+(p[j].x-p[i].x); int x2 = p[j].x+(p[i].y-p[j].y); int y2 = p[j].y+(p[j].x-p[i].x); if(h.find(id(x1,y1))!=h.end() && h.find(id(x2,y2))!=h.end()) res++; } } printf("%d\n",res>>2); } return 0;}
0 0
- poj 2002 hash(平面上若干点能够成多少正方形)
- POJ 2002 Squares(已知平面n点枚举正方形)
- poj 2002 正方形个数 (对点的hash 存储)
- poj 2002 HASH判断正方形
- Poj 2002 Squares (正方形个数 Hash)
- POJ 2002 Squares hash求正方形个数
- POJ 2187 平面上的最远点
- 9.7数学与概率(三)——在二维平面上,有两个正方形,请找出一条直线,能够将这两个正方形对半分
- 由平面上的一些点,求可构成的正方形的数目
- POJ 2002 Squares(计算几何 找正方形 hash枚举)
- POJ 2002-Squares(hash拉链法-正方形个数)
- POJ 2002 点的hash
- 平面上最近点对的距离 POJ 3714
- poj 2187 凸包+平面上点之间最大距离
- poj 2187 旋转卡壳(平面上最远点对)
- POJ 1118 求平面上最多x点共线
- 平面上的点
- 二维平面上最多有多少个点在同一条直线上
- uva10755 - Garbage Heap
- chmod 777修改文件系统权限
- leetcode:Implement Trie (Prefix Tree)
- Android:获取版本号
- 动态规划——小胖办证
- poj 2002 hash(平面上若干点能够成多少正方形)
- leetcode: Basic Calculator
- s3c2440时钟+nandflash拷贝至SDRAM+开启mmu
- 冥想
- leetcode:Integer to English Words
- 新手
- ubuntu 安装配置 JDK
- leetcode:Remove Invalid Parentheses
- android studio中做断点测试