2017杭电多校联赛第二场-Regular polygon (hdu6055)判断点集能构成多少个正方形
2017-07-27 16:26
399 查看
Regular polygon
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
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
题目大意:给你n个点,询问可以构成多少个正方形
解题思路:由题,有n个点,询问可以构成正方形的个数,其实我们只需要判断有没有点能构成正方形,因为正方形的形状特殊性,所以我们知道了正方形的两个点就可以得到其余的两个点,所以我们只需要判断另外两个点在不在我们的点集中即可。
ac代码:
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int N = 1010; const int H = 10007; int ptx , pty ; struct Node { int x; int y; int next; }; Node node ; int cur; int n; long ans; int hashTable[H]; void initHash() { for (int i = 0; i < H; ++i) hashTable[i] = -1; cur = 0; ans = 0; } void insertHash(int x, int y) { int h = (x * x + y * y) % H; node[cur].x = x; node[cur].y = y; node[cur].next = hashTable[h]; hashTable[h] = cur; ++cur; } bool searchHash(int x, int y) { int h = (x * x + y * y) % H; int next; next = hashTable[h]; while (next != -1) { if (x == node[next].x && y == node[next].y) return true; next = node[next].next; } return false; } int main() { while (scanf("%d", &n) != EOF && n) { initHash(); for (int i = 0; i < n; ++i) { scanf("%d%d", &ptx[i], &pty[i]); insertHash(ptx[i], pty[i]); } for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { int x1 = ptx[i] - (pty[i] - pty[j]); int y1 = pty[i] + (ptx[i] - ptx[j]); int x2 = ptx[j] - (pty[i] - pty[j]); int y2 = pty[j] + (ptx[i] - ptx[j]); if (searchHash(x1, y1) && searchHash(x2, y2)) ++ans; } } for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { int x1 = ptx[i] + (pty[i] - pty[j]); int y1 = pty[i] - (ptx[i] - ptx[j]); int x2 = ptx[j] + (pty[i] - pty[j]); int y2 = pty[j] - (ptx[i] - ptx[j]); if (searchHash(x1, y1) && searchHash(x2, y2)) ++ans; } } ans >>= 2; printf("%ld\n", ans); } return 0; }
题目链接:点击打开链接http://acm.hdu.edu.cn/showproblem.php?pid=6055
相关文章推荐
- 2017 杭电多校联赛第二场 1011 Regular polygon(多个点求正方形个数)POJ 2002
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- 2017 杭电多校联赛第二场 1009 TrickGCD(容斥原理) HDU 6053
- 2017 杭电多校联赛第二场 1003 Maximum Sequence(单调队列)HDU 6047
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- 2017杭电多校联赛第二场-Is Derek lying?(hdu6054)
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- 2017杭电多校联赛第二场-Funny Function (hdu6050)快速幂解数学方程
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- 2017 杭电多校联赛第二场 1001 Is Derek lying? HDU 6045
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- 2017杭电多校联赛第二场-TrickGCD (hdu6053)莫比乌斯容斥
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)