Regular polygon HDU

来源:互联网 发布:c语言排队系统 编辑:程序博客网 时间:2024/05/20 10:53
                  

                            Regular polygon 

    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

40 00 11 01 160 00 11 01 12 02 1

Sample Output

12

 由于给出的点都是整数而且要组合成正多边形,只可能组合出正方形,接下来枚举正方形就行了

#include<bits/stdc++.h>using namespace std;int aim[500][500];struct Point{    int x,y;}p[555];int solve(Point a,Point b){    int x=a.x-b.x;    int y=a.y-b.y;    int ans=0;    /*    判断要找的点是否越界以及是否存在    */    if(a.x+y>=0&&a.y-x>=0&&b.x+y>=0&&b.y-x>=0&&aim[a.x+y][a.y-x]&&aim[b.x+y][b.y-x])        ans++;///边以下做一个正方形    if(a.x-y>=0&&a.y+x>=0&&b.x-y>=0&&b.y+x>=0&&aim[a.x-y][a.y+x]&&aim[b.x-y][b.y+x])        ans++;///边以上做一个正方形    return ans;}int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        memset(aim,0,sizeof(aim));        for(int i=0;i<n;i++)        {            int a,b;            scanf("%d%d",&a,&b);            a+=200;///正方形的下标必须大于等于零            b+=200;            p[i].x=a;            p[i].y=b;            aim[a][b]=1;        }        int ans=0;        for(int i=0;i<n;i++)        {            for(int j=i+1;j<n;j++)            {                ans+=solve(p[i],p[j]);            }        }        printf("%d\n",ans/4);///正方形有四条边    }                        ///任意两点都能构成一个正方形    return 0;}




原创粉丝点击