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
一道简单的几何题, 由于输入的是整数点,那么在整数点上只能找到正四边形, 其余的都是无法构造的。所以枚举输入的任意两点,以这两点连成的线段为对角线,看另外两个点是否存在就可以得到答案了。
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; }
相关文章推荐
- Regular polygon HDU 6055
- hdu - 4159 - Regular Convex Polygon - 精度问题
- HDU 4195 Regular Convex Polygon(正多边形)
- hdu-1154 Cutting a Polygon(计算几何综合应用,多模板)
- 2017 多校训练第二场 HDU 6055 Regular polygon
- hdu-6055-Regular polygon
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- hdu 6055 简单计算几何,查找点的四种办法 2017 Multi-University Training Contest - Team 2
- The Number of Triangles Formed by Intersecting Diagonals of a Regular Polygon
- Converting a Polygon ZM shape file to a regular Shape Polygon
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- The Number of Triangles Formed by Intersecting Diagonals of a Regular Polygon
- HDU 6055 Regular polygon
- hdoj 4195 Regular Convex Polygon(余弦定理+正凸多边形性质)
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- HDU 6055 Regular polygon【几何】
- Regular polygon(HDU 6055)
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- hdu 1502 Regular Words DP + 高精度 第一个java
- HDU 5972 Regular Number Bitset优化字符串匹配