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
题意:
在一个 xOy 的坐标轴上给你 n 个点,求你用这些点能连成多少个正多边形 ( 其实就是找能构成多少个正方形 ) 。
思路:
从500个点中枚举两个点,然后寻找另外两个点是否存在。
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int Xa,Xb,Ya,Yb,n,xx,yy;
int x[500+5],y[500+5],vis[200+5][200+5];
int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(vis,0,sizeof(vis));
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
for(int i=0; i<n; i++)
{
scanf("%d %d",&x[i],&y[i]);
x[i]+=100;
y[i]+=100;
vis[x[i]][y[i]]=1;
}
int ans=0;
for(int i=0; i<n; i++)
{
for(int u=0; u<n; u++)
{
if(i==u)
{
continue;
}
else
{
xx=abs(x[i]-x[u]);
yy=abs(y[i]-y[u]);
if(x[i]<=x[u]&&y[i]<=y[u])
{
if(x[i]+yy<=200&&y[i]-xx>=0&&x[u]+yy<=200&&y[u]-xx>=0)
if(vis[x[i]+yy][y[i]-xx]==1&&vis[x[u]+yy][y[u]-xx]==1)
{
ans++;
}
if(x[i]-yy>=0&&y[i]+xx<=200&&x[u]-yy>=0&&y[u]+xx<=200)
if(vis[x[i]-yy][y[i]+xx]==1&&vis[x[u]-yy][y[u]+xx]==1)
{
ans++;
}
}
else if(x[i]<x[u]&&y[i]>y[u])
{
if(x[i]+yy<=200&&y[i]+xx<=200&&x[u]+yy<=200&&y[u]+xx<=200)
if(vis[x[i]+yy][y[i]+xx]==1&&vis[x[u]+yy][y[u]+xx]==1)
{
ans++;
}
if(x[i]-yy>=0&&y[i]-xx>=0&&x[u]-yy>=0&&y[u]-xx>=0)
if(vis[x[i]-yy][y[i]-xx]==1&&vis[x[u]-yy][y[u]-xx]==1)
{
ans++;
}
}
}
}
}
printf("%d\n",ans/4);
}
return 0;
}
本文介绍了一种通过枚举点集中的点来检测能够构成的正多边形数量的算法,特别关注于如何判断能否形成正方形。该算法适用于不超过500个点的数据集,并提供了完整的C++实现代码。
560

被折叠的 条评论
为什么被折叠?



