2017 HDU 多校联合赛 Regular polygon

本文介绍了一种通过枚举点集中的点来检测能够构成的正多边形数量的算法,特别关注于如何判断能否形成正方形。该算法适用于不超过500个点的数据集,并提供了完整的C++实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值