POJ 2002 Squares [hash]】的更多相关文章

Squares Time Limit: 3500MS   Memory Limit: 65536K Total Submissions: 16631   Accepted: 6328 Description A square is a 4-sided polygon whose sides have equal length and adjacent sides form 90-degree angles. It is also a polygon such that rotating abou…
id=2002">Squares 很好的一道二分,事实上本来我是没有思路的,看了基神的题解之后才似乎明确了点. 题意:给出最多有1000个点,问这些点能够组成多少个正方形 分析:先想想怎么推断正方形吧.假如我如今有四个点A,B,C,D,由于边不一定是平行于x轴的.可能是倾斜的,怎样推断四个点组成的四边形是正方形呢?以A点为中心,AB为轴,绕A点顺时针或者逆时针转动90度,就能够得到一个点D' , 相同的方法.以B 点为中心,BA为轴.绕B点顺时针或者逆时针转动90度.就能够得到一个点C'…
http://poj.org/problem?id=2002 只能说hash比二分快很多.随便一个hash函数都可以完爆二分. 判断是否存在正方形思路如下: 1.枚举任意两个点,作为正方形的一条边,那么,整个正方形就确定了,有两个方向. 因为, 设枚举的坐标为(x1, y1) & (x2, y2),所求的坐标是和x1,y1这个点相连,那么有方程如下. 1.垂直,向量积是0 2.边长相等,然后距离公式化简. 即可解出剩下的两个点. 然后要注意两个点要在正方形的同一侧,不然变了平行四边形了. 唤醒了…
题目链接: http://poj.org/problem?id=2002 #include <stdio.h> #include <string.h> ; struct Hash_table { int x, y; struct Hash_table *next; }*Hash[prime]; void Hash_insert(int x, int y) { int key = (x + y) % prime; if(Hash[key] == NULL) { Hash[key] =…
经典好题. 题意是要我们找出所有的正方形.1000点,只有枚举咯. 如图,如果我们知道了正方形A,B的坐标,便可以推测出C,D两点的坐标.反之,遍历所有点作为A,B点,看C,D点是否存在.存在的话正方形数+1. 假设A点坐标为(x1,y1),B点坐标为(x2,y2),则根据三角形全等,易知 C点坐标:( x1+(y2-y1),y1-(x2-x1) ) D点坐标:( x2+(y2-y1),y2-(x2-x1) ) 当然,如果我们遍历任意两个点,一个正方形将会被计数四次(四条边).我们可以只判断斜率…
Squares Time Limit: 3500MS   Memory Limit: 65536K Total Submissions: 15489   Accepted: 5864 Description A square is a 4-sided polygon whose sides have equal length and adjacent sides form 90-degree angles. It is also a polygon such that rotating abou…
题目 http://poj.org/problem?id=2002 题意 已知平面内有1000个点,所有点的坐标量级小于20000,求这些点能组成多少个不同的正方形. 思路 如图,将坐标按照升序排列后,首先枚举p1,p2, 并判断p2是否在p1正下方或者左上角(因为每个正方形只有一条最右边或者是右下的边),按照下图计算p3,p4,判断p3,p4是否存在即可. 感想 排序时要注意和左上角这个信息相符,刚写完时用的是左下角,与升序排序不符合,会遗失部分正方形. 代码 #include <cstdio…
Squares Time Limit: 3500MS   Memory Limit: 65536K Total Submissions: 15137   Accepted: 5749 Description A square is a 4-sided polygon whose sides have equal length and adjacent sides form 90-degree angles. It is also a polygon such that rotating abou…
二分.... Squares Time Limit: 3500MS Memory Limit: 65536K Total Submissions: 14530 Accepted: 5488 Description A square is a 4-sided polygon whose sides have equal length and adjacent sides form 90-degree angles. It is also a polygon such that rotating a…
题目大意: 给定1000个点,寻找有多少组四点对能组成正方形 这里的题目跟上一道做的找平行四边形类似但想法却又不相同的方法 这里找任意2个点形成的一条边,那么可以根据这两个点,找到能和他们组成正方形剩下的两个点的位置,根据hash表去搜索,如果这两个位置存在自己需要的点,说明这种方案可行 添加查找均交给hash表,这样可以实现O(n*n)的复杂度 最后因为每个正方形因为有4条边被访问了4次,所以总的答案要除以4 #include <cstdio> #include <cstring>…