您的位置:首页 > 编程语言 > Go语言

Regular polygon HDU - 6055

2017-07-27 19:42 393 查看
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

一道简单的几何题, 由于输入的是整数点,那么在整数点上只能找到正四边形, 其余的都是无法构造的。所以枚举输入的任意两点,以这两点连成的线段为对角线,看另外两个点是否存在就可以得到答案了。

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <math.h>
using namespace std;
int n;
struct point{
int x, y;
};
point v[510];
int map1[500][500];
bool check(int x)
{
if (-100 <= x && x <= 100)
return true;
else return false;
}
int main()
{
while(scanf("%d", &n) != EOF) {
memset(map1, 0, sizeof(map1));
for (int i = 1; i <= n; i++) {
scanf("%d%d", &v[i].x, &v[i].y);
map1[v[i].x+100][v[i].y+100] = 1;
}
long long int sum = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) if (i != j){
int x1 = v[j].x + v[i].x;
int y1 = v[j].y + v[i].y;
int x2 = (v[j].y - v[i].y + x1) ;
int y2 = (v[i].x - v[j].x + y1) ;
if (x2 % 2 != 0 || y2 % 2 != 0) continue;
x2 /= 2;
y2 /= 2;
if (check(x2) && check(y2) && map1[x2+100][y2+100]) {
int x3 = (v[i].y - v[j].y + x1);
int y3 = (v[j].x - v[i].x + y1);
if (x3 % 2 != 0 || y3 % 2 != 0) continue;
x3 /= 2;
y3 /= 2;
if (check(x3) && check(y3) && map1[x3+100][y3+100])
sum++;
}
}
}
cout <<sum/4<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  计算几何 acm