题目:
Problem Description
On a two-dimensional plane, give you n integer points. Your task is to figure out how many different regular polygon these points can make.
Input
The input file consists of several test cases. Each case the first line is a numbers N (N <= 500). The next N lines ,each line contain two number Xi and Yi(-100 <= xi,yi <= 100), means the points’ position.(the data assures no two points share the same position.)
Output
For each case, output a number means how many different regular polygon these points can make.
Sample Input
4 0 0 0 1 1 0 1 1 6 0 0 0 1 1 0 1 1 2 0 2 1
Sample Output
1 2
思路:赛后看了题解才知道,平面坐标系上,坐标为整数的情况下,n个点组成正n边形时,只可能组成正方形。这样就简单多了。自己选择两个点,看是否有另外两个点(可能在左边,也可能在右边)能和它们组成正方形。动手画一下就可以推出另外两个点的坐标。实践出真知!!!
CODE:
#include<bits/stdc++.h>
using namespace std;
struct node
{
int x,y;
}q[505];
int vis[500][500];
int fun(node a,node b)
{
int x=a.x-b.x,y=a.y-b.y;
int num=0;
if(a.x+y>=0&&a.y-x>=0&&b.x+y>=0&&b.y-x>=0&&vis[a.x+y][a.y-x]&&vis[b.x+y][b.y-x]) num++;
if(a.x-y>=0&&a.y+x>=0&&b.x-y>=0&&b.y+x>=0&&vis[a.x-y][a.y+x]&&vis[b.x-y][b.y+x]) num++;
return num;
}
int main()
{
int n,i,j,a,b;
while(~scanf("%d",&n)){
memset(vis,0,sizeof(vis));
for(i=0;i<n;i++){
scanf("%d%d",&a,&b);
q[i].x=a+100;q[i].y=b+100;
vis[q[i].x][q[i].y]=1;
}
int num=0;
for(i=0;i<n;i++) for(j=i+1;j<n;j++) num+=fun(q[i],q[j]);
printf("%d\n",num/4);
}
return 0;
}