Regular polygon(HDU 6055)

Regular polygon

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


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


 //题意:二维平面上给N个整数点,问能构成几个不同的正多边形。

//思路:这种正多边形只能是正四边形,即正方形(因为给的位置点的坐标都是整数,其他多边形不可能每条边都相同,好像有论文证明的QAQ)。这样问题就简化了很多。





把这几种情况考虑全就行,注意菱形不是正4变形...因为这个WA了无数发...,这题应该是team2最水的题之一了,然而WA了20发...20发...

还有一点就是坐标是可能为负的(但>= -100),所以用 map[][]去存的时候要点的坐标+105,不然map[][]这2个[][]里的数字会是负的,会RE...

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;

const int MAX = 600;
const int INF = -1e9;

typedef struct {
	int x, y;
}Point;

int n;
long long sum;
int map[3000][3000];
int maxx, maxy;
Point point[MAX];

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

void find()
{
	int i, j, k;
	for (i = 0; i < n; i++)
	{
		if (point[i].x == maxx || point[i].y == maxy)
			continue;
		for (j = i + 1; j < n; j++)
		{
			if (point[j].x <= point[i].x)
				continue;
			if (point[j].y <= point[i].y)
				continue;
			int len = point[j].x - point[i].x;
			int leny = point[j].y - point[i].y;

			if (map[point[i].x + len + 105][point[i].y + leny + 105] == 1 && map[point[i].x + leny + 105][point[i].y - len + 105] == 1 && map[point[i].x + len + leny + 105][point[i].y + leny - len + 105] == 1)
			{
				sum++;
			}
			
			if (point[j].y == point[i].y + len)
			{
				if (map[point[i].x + len + 105][point[i].y + 105] == 1 && map[point[i].x + 105][point[i].y + len + 105] == 1 && map[point[i].x + len + 105][point[i].y + len + 105] == 1)
				{
					sum++;
				}
			}
		}
	}
}

int main()
{
	while (scanf("%d", &n) != EOF)
	{
		sum = 0;
		maxx = INF;
		maxy = INF;
		memset(map, 0, sizeof(map));
		for (int i = 0; i < n; i++)
		{
			scanf("%d%d", &point[i].x, &point[i].y);
			int x = point[i].x + 105;
			int y = point[i].y + 105;
			map[x][y] = 1;
			if (point[i].x > maxx)
				maxx = point[i].x;
			if (point[i].y > maxy)
				maxy = point[i].y;
		}
		sort(point, point + n, cmp);
		find();
		printf("%lld\n", sum);
	}
	return 0;
}




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值