2017 Multi-University Training Contest - Team 2 - 1011

Regular polygon
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1123 Accepted Submission(s): 420

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

题目连接

题目大意:给你n个点(x,y)其范围是-100<=x,y<=100 都为整数。然后让你求这些点能构成多少个正多边形。
解题思路:发现只有正方形的顶点才能都在整数点上面(求π的时候就是有正多边形割圆,应该是这样证明的)这样这个题目就转变成了求一共有多少个正方形。刚开始的时候想到了递归发现蠢得要死,正解应该是遍历任意的两个点然后可以根据如果存在正方形就能找出那两个点与与已知点的关系(可以画小方格把点放在小格子的交点找出其对应的关系),因为一个正方形有四条边所以一个正方形重复4次所以令最后的结果除以4就是最后的结果。

AC代码(标程代码):

#include<bits/stdc++.h>
#define mk make_pair
using namespace std;
const int N = 1e3 + 5;


map< pair<int, int>, bool> M;
int x[N], y[N], n, ans;


int main()
{
    int T;
    while(scanf("%d", &n)!=EOF)
    {
        ans=0;
        M.clear();
        for(int i=1;i<=n;i++)
        {
            scanf("%d %d",&x[i],&y[i]);
            M[mk(x[i],y[i])]=1;
        }
        for(int i = 1; i <= n; i++)
        {
            for(int j = i+1; j <= n; j++)
            {
                int dx = y[j] - y[i];
                int dy = x[i] - x[j];
                int ok=0;
                if(M.count(mk(x[i]+dx,y[i]+dy)))
                {
                    ok++;
                }
                if(M.count(mk(x[j]+dx,y[j]+dy)))
                {
                    ok++;
                }
                if(ok==2)  ans++;
                ok=0;
                if(M.count(mk(x[i]- dx,y[i]-dy)))
                {
                    ok++;
                }
                if(M.count(mk(x[j]-dx,y[j]-dy)))
                {
                    ok++;
                }
                if(ok==2)  ans++;
            }
        }
        printf("%d\n",ans/4);
    }
    return 0;
}

此外还可以用数组来求做一个用来标记的二维数组。但是要注意数组的越界问题。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值