2017多校训练第二场 hdu6055 Regular polygon (几何+暴力)

多校训练第二场 hdu6055 Regular polygon

Time Limit: 3000/1000 MS (Java/Others)    
Memory Limit: 65536/65536 K (Java/Others)

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

样例理解:
多组测试样例,每组第一行表示有4(n)个点,接下来的n行描述了这些点的坐标(x,y),问这些点可以构成多少个正多边形。例如(0,0),(0,1),(1,0),(1,1)就可以构成1个正方形。

算法:开始比赛以后看的第一题(对就是因为它题面单词比较少),然后一看就觉得可做,便找来队友讨论这个题,尝试了一下发现好像除了正方形,其它正多边形都是无法在坐标轴上的整点构造出来的。理论验证了三角形的情况(利用cos的值),于是就大胆猜测按照只能构成正方形的去写了,队友胸有成竹打算直接暴力枚举,半个小时以后1A,还是很稳的。

AC代码:

#include <iostream>
#include<cstring>
using namespace std;
typedef long long LL;
typedef pair<int,int>P;

int cnt[205][205];
P p[505];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n,x,y;
    while(cin >> n){
        memset(cnt,0,sizeof(cnt));
        for(int i = 0;i < n;i++){
            cin >> x >> y;
            x += 100;
            y += 100;
            p[i].first = x ;
            p[i].second = y;
            cnt[x][y] = 1;
        }
        LL res = 0;
        for(int i = 0;i < n - 1;i++){
            for(int  j = i + 1;j < n;j++){
                int a = p[i].first;
                int b = p[i].second;
                int c = p[j].first;
                int d = p[j].second;
                int x1 = c + b - d;
                int y1 = d + c - a;
                int x2 = a + b - d;
                int y2 = c + b - a;

                if(x1 >= 0 && x1 <= 200 && y1 >= 0 && y1 <= 200 && x2 >= 0 && x2 <= 200 && y2 >= 0 && y2 <= 200 &&
                   cnt[x1][y1] != 0 && cnt[x2][y2] != 0 ) res++;
                x1 = d + c - b;
                y1 = d + a - c;
                x2 = a + d - b;
                y2 = a + b - c;
                if(x1 >= 0 && x1 <= 200 && y1 >= 0 && y1 <= 200 && x2 >= 0 && x2 <= 200 && y2 >= 0 && y2 <= 200 &&
                cnt[x1][y1] != 0 && cnt[x2][y2] != 0 )
                    res++;
            }
        }
        cout << res / 4 << endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值