HDU6055——多校2017

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6055

Regular polygon

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


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
 

Recommend
liuyiding

题意:在二维平面内有N个点,判断这n个点能组成多少个正多边形

思路:开始也很懵,不过后来知道坐标是整数点的正多边形只有正方形之后,思路清晰了很多。

贴上一份当时队友的代码:

#include<iostream>
#include<sstream>
#include<fstream>
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
#define si(x) scanf("%d", &x)
#define sii(x,y) scanf("%d %d", &x, &y)
#define sl(x) scanf("%ld", &x)
#define sll(x,y) scanf("%ld %ld", &x, &y)
#define fe1(i, a, b) for(int i = a; i <= b; i++)
#define fu(i, a, b) for(int i = a; i < b; i++)
#define MP(x, y) make_pair(x, y)
typedef pair<int , int> pii;
typedef long long LL;
typedef unsigned long long LLu;
const int maxn = 33;
const int inf = 0x3f3f3f3f;
using namespace std ;
#define eqs 1e-9
struct node{
    double x , y ;
}p[1100] ;
bool cmp(node a,node b)
{
    return ( a.x < b.x || ( a.x == b.x && a.y < b.y ) ) ;
}
bool judge(double x,double y,int n)
{
    int low = 0 , mid , high = n-1 ;
    while( low <= high )
    {
        mid = (low + high) / 2 ;
        if( fabs(p[mid].x-x) < eqs && fabs(p[mid].y-y) < eqs )
            return true ;
        else if( p[mid].x-x > eqs || ( fabs(p[mid].x-x) < eqs && p[mid].y-y > eqs ) )
            high = mid - 1 ;
        else
            low = mid + 1 ;
    }
    return false ;
}
int main()
{
    int n , i , j , num ;
    double x , y , xx , yy ;
    while(~scanf("%d", &n))
    {
        num = 0 ;
        for(i = 0 ; i < n ; i++)
        {
            scanf("%lf %lf", &p[i].x, &p[i].y) ;
        }
        sort(p,p+n,cmp) ;
        for(i = 0 ; i < n ; i++)
        {
            for(j = i+1 ; j < n ; j++)
            {
                if( i == j ) continue ;
                x = (p[i].x+p[j].x)/2 ;
                y = (p[i].y+p[j].y)/2 ;
                xx = p[i].x - x ;
                yy = p[i].y - y ;
                if( judge(x+yy,y-xx,n) && judge(x-yy,y+xx,n) )
                {
                    num++ ;
                }
            }
        }
        printf("%d\n", num/2) ;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值