杭电多校 1011 Regular polygon! 题解报告

这里写图片描述
题目意思
很简单的题目意思,给你一系列的点的坐标,问你可以用这些点构造多少正多边形
其实就是找正方形的个数 这个是一个结论
等我晚上吃完饭回来 让总结
先上代码:

#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1000+5;
int N,ans;
struct SPoint {
    double x,y;
    SPoint() {}
    SPoint(int xx,int yy) : x(xx), y(yy) {}
    bool operator < (const SPoint& p) const {
        if(x == p.x) return y < p.y;
        return x < p.x;
    }
    bool operator == (const SPoint& p) const {
        return x==p.x&&y==p.y;
    }
}pnt[maxn];
//任意点(x,y),绕一个坐标点(rx0,ry0)逆时针旋转a角度后的新的坐标设为(x0, y0),有公式:
//x0= (x - rx0)*cos(a) - (y - ry0)*sin(a) + rx0 ;
//y0= (x - rx0)*sin(a) + (y - ry0)*cos(a) + ry0 ;
void transXY(SPoint A, SPoint B, SPoint &C, int f) {
    int tx = B.x - A.x, ty = B.y - A.y;
    C.x = A.x - ty * f;
    C.y = A.y + tx * f;
}
int main() {
    //freopen("input.in","r",stdin);
    while(~scanf("%d",&N)&&N)
    {
        ans = 0;
        for(int i = 0;i < N;i++) scanf("%lf %lf",&pnt[i].x,&pnt[i].y);
        sort(pnt,pnt+N);
        for(int i = 0;i < N-3;i++)                                                  //①
        {
            for(int j = i+1;j < N-2;j++)                                            //②
            {
                SPoint C,D;
                transXY(pnt[i],pnt[j],C,1);
                transXY(pnt[j],pnt[i],D,-1);
                if(binary_search(pnt+j,pnt+N,C)&&binary_search(pnt+j,pnt+N,D)) ans++;  //③
                transXY(pnt[i],pnt[j],C,-1);
                transXY(pnt[j],pnt[i],D,1);
                if(binary_search(pnt+j,pnt+N,C)&&binary_search(pnt+j,pnt+N,D)) ans++;  //④  
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值