hdu6055Regular polygon(2017高校2)

给定二维平面上不超过500个整数坐标点,求能构成多少种不同的正多边形。输入包含多组测试用例,每组先给出点的数量N,然后依次给出N个点的坐标。对于每组数据,输出能构成的不同正多边形数量。样例输入与输出展示了如何判断并计算正方形组合的情况。
摘要由CSDN通过智能技术生成

Regular polygon

Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1892 Accepted Submission(s): 743

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

题意:正方形,在二维平面给你若干个点,问有多少个正方组合?

由于给的数均是整数,因此能判定只要给出两个点就能判断是否存在正方形:
取x1,y1;x2,y2两个点,我们能这样计算出x3,y3;,x4,y4两个点,只有存在这两个点才能组成正方形。

这里写图片描述

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
int check(int x1,int y1)
{
    if(x1>=0&&x1<=200&&y1>=0&&y1<=200)
    return 1;
    return 0;
}
struct node
{
    int x,y;
}point[550];
int main()
{
    int n;
    int vist[210][210];
    while(scanf("%d",&n)!=EOF)
    {
        memset(vist,0,sizeof(vist));
        for(int i=0;i<n;i++)
        {
            scanf("%d %d",&point[i].x,&point[i].y);
            point[i].x+=100;
            point[i].y+=100;
            vist[point[i].x][point[i].y]=1;
        }
        int ans=0;
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                //if(i==j)continue;
                int x1=point[i].x;
                int y1=point[i].y;
                int x2=point[j].x;
                int y2=point[j].y;
                int x3=x1+(y1-y2);
                int y3= y1-(x1-x2);
                int x4=x2+(y1-y2);
                int y4= y2-(x1-x2);
                if(check(x3,y3)&&check(x4,y4)&&vist[x3][y3]&&vist[x4][y4])
                {
                    ans++;
                }
                x3=x1-(y1-y2);
                y3= y1+(x1-x2);
                x4=x2-(y1-y2);
                y4= y2+(x1-x2);
                if(check(x3,y3)&&check(x4,y4)&&vist[x3][y3]&&vist[x4][y4])
                {
                    ans++;
                }
            }
        }
        cout<<ans/4<<endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值