2017 Multi-University Training Contest - Team 2 Regular polygon

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6055


题目大意: 在xy坐标轴上给n个点, n <= 500 (-100 <= xi, yi <= 100) 问这些点可以组成多少个不同的正多边形。


解题思路: 正多边形每个点都是整点的只有正方形, 所以暴力枚举两个点去判断是否可以形成正方形就可以了。 复杂度为O(n^2)。


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using  namespace std;
const int MaxN = 1000;

struct XX{
	int x, y;
}a[MaxN + 5];
bool vis[MaxN + 5][MaxN + 5];
int n, ans;

bool cmp(XX a, XX b){
	if(a.x == b.x) return a.y < b.y;
	else return a.x < b.x;
}

int main(){
	while(~scanf("%d", &n)){
		memset(vis, 0, sizeof(vis));
		ans = 0;
		for(int i = 1; i <= n; i++){
			scanf("%d %d", &a[i].x, &a[i].y);
			a[i].x += 100, a[i].y += 100;
			vis[a[i].x][a[i].y] = true;
		}
		sort(a + 1, a + 1 + n, cmp);
		for(int i = 1; i < n; i++){
			for(int j = i + 1; j <= n; j++){
				int lx = a[i].x - a[j].x;
				int ly = a[i].y - a[j].y;
				if(a[i].x - ly < 0 || a[j].x - ly < 0) continue;
				if(vis[a[i].x - ly][a[i].y + lx] && vis[a[j].x - ly][a[j].y + lx]) ans++;
			}
		}
		printf("%d\n", ans / 2);
	}
	return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值