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

2017 Multi-University Training Contest - Team 2:1011&hdu6095、Regular polygon

2017-08-07 09:24 369 查看
题目:

[align=left]Problem Description[/align]
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.
 

[align=left]Input[/align]
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.)
 

[align=left]Output[/align]
For each case, output a number means how many different regular polygon these points can make.
 

[align=left]Sample Input[/align]

4
0 0
0 1
1 0
1 1
6
0 0
0 1
1 0
1 1
2 0
2 1

 

[align=left]Sample Output[/align]

1
2

题意:给出n个点,坐标为整数,问可以组成多少个正多边形?
思路:赛后看了题解才知道,平面坐标系上,坐标为整数的情况下,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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  平面几何
相关文章推荐