Regular polygon
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1087 Accepted Submission(s): 405
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
Source
论文???
被队友先入为主了,刚开始提了一下整数,后来想到死也没想出来,直接暴力了。
#include <iostream>
#include <cstring>
using namespace std;
int n,ans,a,b;
bool mapc[205][205];
struct point
{
int x,y;
};
int judge(point a,point b)
{
int x1 = a.x, y1 = a.y, x2 = b.x, y2 = b.y;
int res = 0;
int x3 = -y2+y1+x1 ,y3 = x2-x1+y1;
int x4 = x3-x1+x2 ,y4 = y3-y1+y2;
int x5 = 2*x1-x3 ,y5 = 2*y1-y3;
int x6 = 2*x2-x4 ,y6 = 2*y2-y4;
if( (x3<=100 && x3>=-100) && (y3<=100 && y3>=-100)
&& (x4<=100 && x4>=-100) && (y4<=100 && y4>=-100)
&& mapc[x3+100][y3+100] && mapc[x4+100][y4+100] )
res++;
if( (x5<=100 && x5>=-100) && (y5<=100 && y5>=-100)
&& (x6<=100 && x6>=-100) && (y6<=100 && y6>=-100)
&& mapc[x5+100][y5+100] && mapc[x6+100][y6+100] )
res++;
return res;
}
point p[505];
int main()
{
while(cin>>n)
{
ans=0;
memset(mapc,0,sizeof(mapc));
for(int i=0;i<n;i++)
{
cin>>a>>b;
p[i].x=a,p[i].y=b;
mapc[a+100][b+100]=1;
}
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
ans+=judge(p[i],p[j]);
cout<<ans/4<<endl;
}
return 0;
}
本文介绍了一种通过暴力搜索算法来找出平面上由给定点构成的不同正多边形数量的方法。输入为若干组测试数据,每组包含一系列二维平面上的整数坐标点;输出则是基于这些点能构成的不同正多边形的数量。
237

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



