17多校contest two 1011Regular polygon ( 计算几何

本文介绍了一种通过坐标判断平面上若干点能否构成正多边形的方法,并给出了一段AC代码实现。该方法主要利用数学公式推导,确定特定条件下正方形的存在可能性。

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

Regular polygon

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

题意

平面上给一组坐标 判断一共可以组成多少个正多边型

题解:

这个道题完全是靠结论的好不 唉
坐标为整数的点 所组成的正多边形 一定是正方形
那么就是已知两个点 枚举另外两个点(两个点可以决定2个正方形
已知(x1,x2) (y1,y2)

x3=x1+(y1-y2) y3= y1-(x1-x2)

x4=x2+(y1-y2) y4= y2-(x1-x2)

x3=x1-(y1-y2) y3= y1+(x1-x2)

x4=x2-(y1-y2) y4= y2+(x1-x2)

AC代码

#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define CLR(a,b) memset(a,(b),sizeof(a))

const int N = 500+10;
bool vis[N<<1][N<<1];
int X[N], Y[N];

int main()
{
    int n;
    while(~scanf("%d",&n)) {
        CLR(vis,false);
        LL k = 0;
        for(int i = 0; i < n; i++) {
            scanf("%d%d",&X[i],&Y[i]);
            vis[N+X[i]][N+Y[i]] = true;
        }
        int x1, x2, x3,
         x4;
        int y1, y2, y3, y4;
        for(int i = 1; i < n; i++) {
            x1 = X[i], y1 = Y[i];
            for(int j = 0; j < i; j++) {
                x2 = X[j], y2 = Y[j];
                x3 = x1 + (y1-y2);
                y3 = y1 - (x1-x2);
                x4 = x2 + (y1-y2);
                y4 = y2 - (x1-x2);
                if(vis[N+x3][N+y3] && vis[N+x4][N+y4]) k++;
                x3 = x1 - (y1-y2);
                y3 = y1 + (x1-x2);
                x4 = x2 - (y1-y2);
                y4 = y2 + (x1-x2);
                if(vis[N+x3][N+y3] && vis[N+x4][N+y4]) k++;
            }
        }
        printf("%lld\n",k/4);
    }
return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值