POJ 2002 几何+hash】的更多相关文章

题目大意: 给定1000个点,寻找有多少组四点对能组成正方形 这里的题目跟上一道做的找平行四边形类似但想法却又不相同的方法 这里找任意2个点形成的一条边,那么可以根据这两个点,找到能和他们组成正方形剩下的两个点的位置,根据hash表去搜索,如果这两个位置存在自己需要的点,说明这种方案可行 添加查找均交给hash表,这样可以实现O(n*n)的复杂度 最后因为每个正方形因为有4条边被访问了4次,所以总的答案要除以4 #include <cstdio> #include <cstring>…
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…
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…
题目链接:http://poj.org/problem?id=2002 题意:给定n个点,问有多少种方法可以组成正方形. 思路:我们可以根据两个点求出对应正方形[有2个一个在两点左边,一个在两点右边]另外两个点的左边.例如 已知:(x1,y1) (x2,y2)则x3=x1+(y1-y2) y3= y1-(x1-x2) x4=x2+(y1-y2) y4= y2-(x1-x2)或x3=x1-(y1-y2) y3= y1+(x1-x2) x4=x2-(y1-y2) y4= y2+(x1-x2) 枚举两…
http://poj.org/problem?id=2002 只能说hash比二分快很多.随便一个hash函数都可以完爆二分. 判断是否存在正方形思路如下: 1.枚举任意两个点,作为正方形的一条边,那么,整个正方形就确定了,有两个方向. 因为, 设枚举的坐标为(x1, y1) & (x2, y2),所求的坐标是和x1,y1这个点相连,那么有方程如下. 1.垂直,向量积是0 2.边长相等,然后距离公式化简. 即可解出剩下的两个点. 然后要注意两个点要在正方形的同一侧,不然变了平行四边形了. 唤醒了…
题目 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…
枚举两个点作为一条边,求出正方形的另外两个点,利用hash查找另外两个点. #include<stdio.h> #include<string.h> #include<stdlib.h> struct node{ int x,y; } point[]; struct hash{ int pos; hash* next; } hashtable[]; int find(int x,int y){ hash* t; ; t=&hashtable[tmp]; ){ ;…
Squares Time Limit: 3500MS   Memory Limit: 65536K Total Submissions: 18493   Accepted: 7124 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 题意:给定一个n个数字组成的序列,然后求出4个数使得a+b+c=d,求d的最大值.其中a,b,c,d要求是给定序列的数,并且不能重复拿同一个位置的数. 思路:先处理a+b,把a+b的组合和在序列的位置存起来.然后枚举d,c计算d-c时候在a+b中出现过.并且a.b.c.d在序列的位置都不同.注意结果可能爆int. #include<iostream> #include<cstring> #include<…