PKU 3432 Count Squares

Count Squares
Time Limit: 3000MS
Memory Limit: 65536K
Total Submissions: 1331
Accepted: 552

Description

Given a set of points with integer coordinates xi, yi, i = 1...N, your program must find all the squares having each of four vertices in one of these points.

Input

Input file contains integer N followed by N pairs of integers xi yi.

Constraints

-104xi, yi ≤ 104, 1 ≤ N ≤ 2000. All points in the input are different.

Output

Output file must contain a single integer — number of squares found.

Sample Input

Sample input 1
4 0 0 4 3 -3 4 1 7
Sample input 2
9
1 1 1 2 1 3
2 1 2 2 2 3
3 1 3 2 3 3

Sample Output

Sample output 1
1
Sample output 2
6

Hint

Bold texts appearing in the sample sections are informative and do not form part of the actual data.

Source

Northeastern Europe 2005, Far-Eastern Subregion

题目意思很简单,给一群不同的点,求这些点最多组成了几个正方形。

每此枚举2个点,作为正方行的一条边,然后顺时针/逆时针旋转90度(利用相对坐标来计算),得到另外2个点的坐标,查询HASH看这2个点如果都存在那么cnt++;
最后cnt/4,因为一个正方形被算过4次

  1. for(i=0;i<n;i++)
  2.             for(j=0;j<n;j++)
  3.             {
  4.                 if(i==j)continue;
  5.                                 //下面是重点-坐标变换
  6.                 TMP.x=P[j].y-P[i].y+P[j].x;
  7.                 TMP.y=P[i].x-P[j].x+P[j].y;
  8.                 if(isin(TMP))//isin查询HASH表中点是否存在
  9.                 {
  10.                                         //坐标变换,得到另一个点
  11.                     TMP.x+=(P[i].x-P[j].x);
  12.                     TMP.y+=(P[i].y-P[j].y);
  13.                     if(isin(TMP))
  14.                         cnt++;
  15.                 }
  16.             }
  17.         printf("%d/n",cnt/4);

你可能感兴趣的:(File,Integer,ini,input,each,output)