HDU6055(Regular polygon)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6055

有500个整数点的坐标,问总共欧多少个正多边形。

一个结论:若一个正多边形的点都是整数点,那么该正多边形是正四边形(具体证明见杨景钦在2017的国家队论文)。

首先,把点排序。

然后,枚举两个点,利用向量平行和垂直的关系以及正四边形各边长度相等计算出另外两个点,二分判断这两个点是否存在。

最后累加结果除以4(正四边形的每个边都枚举过一遍,所以除以4)。

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

const int maxn = 510;

struct Point{
    int x, y;
    Point() {}
    Point(int x, int y):x(x), y(y) {}
};
typedef Point Vector;

Point a[maxn];
int n;

Vector operator - (Point A, Point B){
    return Vector(A.x-B.x, A.y-B.y);
}

bool operator == (Point A, Point B){
    return A.x == B.x && A.y == B.y;
}

int Dot(Vector A, Vector B){
    return A.x*B.x + A.y*B.y;
}

int Cha(Vector A, Vector B){
    return A.x*B.y - A.y*B.x;
}

int cmp(const Point& A, const Point& B){
    if (A.x != B.x){
        return A.x < B.x;
    }else{
        return A.y < B.y;
    }
}

bool Bin(Point key){
    int l = 0;
    int r = n-1;
    while (l <= r){
        int m = (l + r) >> 1;
        if (key == a[m]){
            return true;
        }
        if (cmp(a[m], key)){
            l = m + 1;
        }else{
            r = m - 1;
        }
    }
    return false;
}

int main()
{
    while (~scanf("%d", &n)){
        for (int i=0; i<n; i++) scanf("%d%d", &a[i].x, &a[i].y);

        sort(a, a+n, cmp);

        int cnt = 0;
        for (int i=0; i<n; i++)
            for (int j=i+1; j<n; j++)
        {
            Point A = a[i];
            Point B = a[j];
            Vector AB = A - B;
            Point C1 = Point(B.x + AB.y, B.y - AB.x);
            Point C2 = Point(B.x - AB.y, B.y + AB.x);
            Point D1 = Point(A.x + AB.y, A.y - AB.x);
            Point D2 = Point(A.x - AB.y, A.y + AB.x);
            Vector CD1 = C1 - D1;
            Vector CD2 = C2 - D2;

            if (Cha(CD1, AB) != 0){
                Point T = C1; C1 = C2; C2 = C1;
                CD1 = C1 - D1;
                CD2 = C2 - D2;
            }
            if (Bin(C1) && Bin(D1)){
                cnt++;
            }
            if (Bin(C2) && Bin(D2)){
                cnt++;
            }
        }

        cout << cnt/4 << endl;
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值