HDU-6055-Regular polygon

本文介绍了一个算法问题:给定二维平面上的整数坐标点集,任务是找出这些点能构成的不同正多边形的数量。输入包括多个测试用例,每个用例给出一系列点坐标;输出则是每个用例中可以构成的不同正多边形数量。

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

Regular polygon

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


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
 

Source
 

解题代码
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
struct node
{
    int x,y;
}ch[505];
int vis[205][205];
int main()
{
    int N;
    while(scanf("%d",&N)!=EOF)
    {
        memset(vis,0,sizeof(vis));
        for(int i=1;i<=N;i++)
        {
            scanf("%d%d",&ch[i].x,&ch[i].y);
            ch[i].x+=100;
            ch[i].y+=100;
            vis[ch[i].x][ch[i].y]=1;
        }
        int count1=0;
        for(int i=1;i<=N;i++)
            for(int j=i+1;j<=N;j++)
        {
            int x1=ch[i].x;
            int y1=ch[i].y;
            int x2=ch[j].x;
            int y2=ch[j].y;
            int dx=ch[i].x-ch[j].x;
            int dy=ch[i].y-ch[j].y;
            if(x1+dy>=0&&x1+dy<=200&&y1-dx>=0&&y1-dx<=200&&x2+dy>=0&&x2+dy<=200&&y2-dx>=0&&y2-dx<=200)
            {
                if(vis[x1+dy][y1-dx]==1&&vis[x2+dy][y2-dx]==1)
                    count1++;
            }
            if(x1-dy>=0&&x1-dy<=200&&y1+dx>=0&&y1+dx<=200&&x2-dy>=0&&x2-dy<=200&&y2+dx>=0&&y2+dx<=200)
            {
                if(vis[x1-dy][y1+dx]==1&&vis[x2-dy][y2+dx]==1)
                    count1++;
            }
        }
        printf("%d\n",count1/4);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值