2017 Multi-University Training Contest - Team 2:1011&hdu6095、Regular polygon

题目:

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个点,坐标为整数,问可以组成多少个正多边形?

思路:赛后看了题解才知道,平面坐标系上,坐标为整数的情况下,n个点组成正n边形时,只可能组成正方形。这样就简单多了。自己选择两个点,看是否有另外两个点(可能在左边,也可能在右边)能和它们组成正方形。动手画一下就可以推出另外两个点的坐标。实践出真知!!!!!!!

CODE:

#include<bits/stdc++.h>
using namespace std;
struct node
{
        int x,y;
}q[505];
int vis[500][500];
int fun(node a,node b)
{
        int x=a.x-b.x,y=a.y-b.y;
        int num=0;
        if(a.x+y>=0&&a.y-x>=0&&b.x+y>=0&&b.y-x>=0&&vis[a.x+y][a.y-x]&&vis[b.x+y][b.y-x]) num++;
        if(a.x-y>=0&&a.y+x>=0&&b.x-y>=0&&b.y+x>=0&&vis[a.x-y][a.y+x]&&vis[b.x-y][b.y+x]) num++;
        return num;
}
int main()
{
        int n,i,j,a,b;
        while(~scanf("%d",&n)){
                memset(vis,0,sizeof(vis));
                for(i=0;i<n;i++){
                        scanf("%d%d",&a,&b);
                        q[i].x=a+100;q[i].y=b+100;
                        vis[q[i].x][q[i].y]=1;
                }
                int num=0;
                for(i=0;i<n;i++) for(j=i+1;j<n;j++) num+=fun(q[i],q[j]);
                printf("%d\n",num/4);
        }
        return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值