HDU6055 Regular polygon +多校联赛第二场

Regular polygon

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


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边形时,只可能组成正方形。

然后根据这个结论来做。

思路
刚开始思路比较深,感觉代码写不出来,后来大神点通了我,瞬间觉得好简单呀; 确定两个点,由正方形坐标关系确定其他两个点的坐标, 看着两个点是否存在,如果存在,这加1
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
int dp[505][505];
struct node
{
    int x,y;
} a[550];
//void fun(int m)
//{
//    for(int i=0;i<m;i++)
//    {
//        for(int j=0;j<m;j++)
//        {
//            dp[i][j]=(a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y);
//        }
//    }
//}
int cmp(node aa,node bb)//排序
{
    if(aa.x==bb.x)
        return aa.y<bb.y;
    return aa.x<bb.x;
}
int main()
{
    int n,sum;
    int x1,y1,x2,y2;
    while(scanf("%d",&n)!=EOF)
    {
        memset(dp,0,sizeof(dp));
        for(int i=0; i<n; i++)
        {
            scanf("%d%d",&a[i].x,&a[i].y);
            a[i].x+=100;                  //平移坐标
            a[i].y+=100;
            dp[a[i].x][a[i].y]=1;       //标记出现的点
        }
        sort(a,a+n,cmp);
        sum=0;
        for(int i=0; i<n; i++)
        {
            for(int j=i+1; j<n; j++)
            {
                if(a[j].y>a[i].y)
                {
                    if(a[i].x<=a[j].x&&a[i].y<=a[j].y)
                    {                                  //确定其他的两个点
                        x1=(a[j].x+a[j].y-a[i].y);
                        y1=(a[j].y-(a[j].x-a[i].x));
                        x2=(a[i].x+a[j].y-a[i].y);
                        y2=(a[i].y-(a[j].x-a[i].x));
                        if(dp[x1][y1]==1&&dp[x2][y2]==1)
                        {
                            sum++;
                        }

                    }
                }
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}




  
  
    
    


  
  

  
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值