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 about its centre by 90 degrees gives the same polygon. It is not the only polygon with the latter property, however, as a regular octagon also has this property.
So we all know what a square looks like, but can we find all possible squares that can be formed from a set of stars in a night sky? To make the problem easier, we will assume that the night sky is a 2-dimensional plane, and each star is specified by its x and y coordinates.

Input

The input consists of a number of test cases. Each test case starts with the integer n (1 <= n <= 1000) indicating the number of points to follow. Each of the next n lines specify the x and y coordinates (two integers) of each point. You may assume that the points are distinct and the magnitudes of the coordinates are less than 20000. The input is terminated when n = 0.

Output

For each test case, print on a line the number of squares one can form from the given stars.

Sample Input

4
1 0
0 1
1 1
0 0
9
0 0
1 0
2 0
0 2
1 2
2 2
0 1
1 1
2 1
4
-2 5
3 7
0 0
5 2
0

Sample Output

1
6
1 就是看看给出的点能组成几个正方形;
不要四个四个的组合,想也会超时,任意两个组合,然后计算出另外两个点;
再去查询是否存在;结果要除以4的;
 #include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
bool x[][];//我才不告诉你其实数据是-2000--2000
int si[],sj[];
int f(int a,int b)
{
if(x[a+][b+])
return ;
return ;
}
int main()
{
int a,b,i,j,n,sum;
int x1,y1,x2,y2,x3,y3,x4,y4;
while(scanf("%d",&n)&&n)
{
sum=;
memset(x,,sizeof(x));
for(i=; i<n; i++)
{
scanf("%d %d",&a,&b);
si[i]=a;
sj[i]=b;
x[a+][b+]=;
}
for(i=; i<n; i++)
{
x1=si[i];
y1=sj[i];
for(j=; j<i; j++)
{
x2=si[j];
y2=sj[j];
x3=x1+(y1-y2);//计算剩下两个点
y3= y1-(x1-x2);
x4=x2+(y1-y2);
y4= y2-(x1-x2);
if(f(x3,y3)&&f(x4,y4))
sum++;
x3=x1-(y1-y2);
y3= y1+(x1-x2);
x4=x2-(y1-y2);
y4= y2+(x1-x2);
if(f(x3,y3)&&f(x4,y4))
sum++;
}
}
printf("%d\n",sum/);//记得除以4
}
return ;
}

Squares<哈希>的更多相关文章

  1. Squares(哈希)

    Time Limit: 3500MS   Memory Limit: 65536K Total Submissions: 14328   Accepted: 5393 Description A sq ...

  2. POJ-2002 Squares,哈希模板+数学公式!

                                                           Squares 题意:二维坐标轴给出n个点求有多少个正方形. 要是平时做比赛的话毫无疑问会 ...

  3. POJ 2002 Squares 哈希

    题目链接: http://poj.org/problem?id=2002 #include <stdio.h> #include <string.h> ; struct Has ...

  4. poj 2002 Squares 几何二分 || 哈希

    Squares Time Limit: 3500MS   Memory Limit: 65536K Total Submissions: 15137   Accepted: 5749 Descript ...

  5. URAL - 1486 Equal Squares 二维哈希+二分

    During a discussion of problems at the Petrozavodsk Training Camp, Vova and Sasha argued about who o ...

  6. 【URAL 1486】Equal Squares(二维哈希+二分)

    Description During a discussion of problems at the Petrozavodsk Training Camp, Vova and Sasha argued ...

  7. POJ 2002 Squares 解题报告(哈希 开放寻址 & 链式)

    经典好题. 题意是要我们找出所有的正方形.1000点,只有枚举咯. 如图,如果我们知道了正方形A,B的坐标,便可以推测出C,D两点的坐标.反之,遍历所有点作为A,B点,看C,D点是否存在.存在的话正方 ...

  8. PKU 2002 Squares(二维点哈希+平方求余法+链地址法)

    题目大意:原题链接 给定平面上的N个点,求出这些点一共可以构成多少个正方形. 解题思路: 若正方形为ABCD,A坐标为(x1, y1),B坐标为(x2, y2),则很容易可以推出C和D的坐标.对于特定 ...

  9. poj Squares n个点,共能组成多少个正方形 二分 + 哈希

    题目链接:http://poj.org/problem?id=2002 测试数据: 41 00 11 10 090 01 02 00 21 22 20 11 12 14-2 53 70 05 20 有 ...

随机推荐

  1. calltree查看工程代码中的函数调用关系

    http://blog.csdn.net/elitemouse/article/details/41680113 http://www.tinylab.org/callgraph-draw-the-c ...

  2. tomcat work 目录

    用tomcat作web服务器的时候,部署的程序在webApps下,这些程序都是编译后的程序(发布到tomcat的项目里含的类,会被编译成.class后才发布过来,源文件没有发布过来,但这里的jsp没有 ...

  3. DIV------使用 <div> 元素的网页布局

    <!DOCTYPE html> <html> <head> <style type="text/css"> div#containe ...

  4. gamit10.6问题汇总

    1.在处理精密星历时,提示:old version of file not supported (name svnav.dat) 解决办法:在gamit10.5中不会出现这个问题,10.6中的官方文档 ...

  5. 深入了解java集群技术

    原文源自:http://blog.csdn.net/happyangelling/article/details/6413584 序言 越来越多的关键应用运行在J2EE(Java 2, Enterpr ...

  6. phpstrom+xdebug调试PHP代码

    众所周知开发PHP的IDE种类繁多,然而开发PHP并不能像开发其他语言一样,调试PHP代码对诸多新手来说,搭建调试环境就比较麻烦!其实哈,我发现NuSphere-phped-16.0很强大,集成了很强 ...

  7. JS获取屏幕各种高

    <script language="javascript"> var h = ""; h += " 网页可见区域宽:"+ doc ...

  8. java_设计模式_命令模式_Command Pattern(2016-08-09)

    理解还不到位,先窜出来.等过一阵子再看,再理解. 定义:将一个请求封装成一个对象,从而让你使用不同的请求把客户端参数化,对请求排队或者记录请求日志,可以提供命令的撤销和恢复功能. 类型:行为类模式 类 ...

  9. mysql如何将一个表导出为excel表格

    方法一:进入到mysql的控制台,输入: 1. SELECT * INTO OUTFILE ‘./test.xls‘ FROM tb1 WHERE 1 ORDER BY id DESC  LIMIT ...

  10. 数组去重的三种方法及from方法

    直接上代码: var str="adbbckddwerivka"; var arr=str.split(""); console.log(arr); //ind ...