您的位置:首页 > 大数据 > 人工智能

hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)

2017-07-28 08:21 447 查看

Regular polygon

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

官方题解:



代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

const int maxn=1000+5;
struct point
{
int x,y;
point() {}
point(int a,int b)
{
x=a,y=b;
}
} pt[maxn];
int vis[maxn][maxn];
int n;

point solve(point p1,point p2)
{
int tx=p2.x-p1.x;
4000
int ty=p2.y-p1.y;
return point(p1.x-ty,p1.y+tx);
}

int main()
{
while(~scanf("%d",&n))
{
memset(vis,0,sizeof(vis));
for(int i=0; i<n; ++i)
{
scanf("%d%d",&pt[i].x,&pt[i].y);
pt[i].x+=400;
pt[i].y+=400;
vis[pt[i].x][pt[i].y]=1;
}
int ans=0;
for(int i=0; i<n; ++i)
for(int j=0; j<n; ++j)
{
if(i==j)
continue;
point p1=solve(pt[i],pt[j]);
if(!vis[p1.x][p1.y])
continue;
point p2=solve(p1,pt[i]);
if(vis[p2.x][p2.y])
++ans;
}
printf("%d\n",ans/4);
}
return 0;
}


ps:这种判断正方形的方法也是一种套路。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐