POJ 2002 Squares
2012-11-21 13:10
453 查看
给你1000个点,让你在这些点中,找到4个点,使其成为一个正方形的顶点。问有多少对这种点。
选两个点,看剩下的两个点是否是给出来的,用hash过之,我用的map,差不多。
选两个点,看剩下的两个点是否是给出来的,用hash过之,我用的map,差不多。
#include <iostream> #include <cstdio> #include <cstring> #include <map> #include <algorithm> using namespace std; map<int,int> mp; long long cnt; struct point{ int x; int y; }; point p[2000]; bool cmp(point a, point b) { if(a.x == b.x) return a.y < b.y; return a.x < b.x; } int main() { int i,t1,t2,n,tx,ty,t3,t4,j; while (1) { scanf("%d",&n); if (n == 0) break; cnt=0; mp.clear(); for (i=0; i<n; i++) { scanf("%d%d",&p[i].x,&p[i].y); mp[p[i].x*100000+p[i].y]=1; } sort(p,p+n,cmp); for (i=0; i<n; i++) { for (j=i+1; j<n; j++) { t1=p[i].x+p[i].y-p[j].y; t2=p[i].y-p[i].x+p[j].x; t1=100000*t1+t2; t3=p[j].x+p[i].y-p[j].y; t4=p[j].y-p[i].x+p[j].x; t3=t3*100000+t4; if (mp.find(t1) != mp.end() && mp.find(t3) != mp.end()) cnt++; } } printf("%lld\n",cnt/2); } }
相关文章推荐
- poj 2002 Squares(hash)
- POJ2002 Squares(枚举)
- poj 2002 Squares (hash 拉链 点集)
- poj-2002 Squares
- POJ-2002 Squares 解题报告
- [POJ2002]Squares【平面几何】
- Poj 2002 Squares
- POJ 2002 Squares
- poj 2002 Squares
- poj 2002 Squares
- poj 2002 Squares
- POJ 2002 Squares
- poj2002 Squares
- 【二分查找】-POJ-2002-Squares
- POJ 2002--Squares
- POJ 2002, Squares
- Hash poj2002 Squares
- [POJ2002]Squares(计算几何,二分)
- POJ 2002-Squares(hash拉链法-正方形个数)
- poj 2002 Squares