2017 杭电多校联赛第二场 1011 Regular polygon(多个点求正方形个数)POJ 2002
来源:互联网 发布:长虹pf21800h数据 编辑:程序博客网 时间:2024/06/01 10:17
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
40 00 11 01 160 00 11 01 12 02 1
Sample Output
12跟POJ 2002一模一样。。。则p1 p2 p3 p4组成一个正方形,设p1 = (x1,y1), p2 = (x2, y2),根据向量的旋转公式可以求出p3, p4的坐标为
p3 = (y1 - y2 + x1, x2 - x1 + y1)
p4 = (y1 - y2 + x2, x2 - x1 + y2)
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;const int N = 1010;const int H = 10007;int ptx[N], pty[N];struct Node{ int x; int y; int next;};Node node[N];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;}
阅读全文
1 0
- 2017 杭电多校联赛第二场 1011 Regular polygon(多个点求正方形个数)POJ 2002
- 2017杭电多校联赛第二场-Regular polygon (hdu6055)判断点集能构成多少个正方形
- HDU6055 Regular polygon +多校联赛第二场
- HDU6055 Regular polygon(2017多校第二场)
- 2017 多校训练第二场 HDU 6055 Regular polygon
- HDU 2017 多校联赛2 1011 Regular polygon
- Regular polygon(2017多校联赛2。 计算几何)
- 2017多校联合第二场 1011题 hdu 6055 Regular polygon 计算几何
- 2017多校训练第二场 hdu6055 Regular polygon (几何+暴力)
- HDU6055 Regular polygon(计算几何,2017 HDU多校联赛 第2场)
- HDU 2017多校联赛-Regular polygon
- HDU 6055 Regular polygon (找正方形)
- Hdu6055 Regular polygon(2017多校第2场)
- 2017杭电多校联赛第二场-Maximum Sequence(hdu6047)
- 2017杭电多校联赛第二场-Is Derek lying?(hdu6054)
- 【2017多校第二场】HDU 6055 Regular polygon【几何,枚举】
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest
- hdu6055—Regular polygon(正方形的判定)
- 2017 Multi-University Training Contest
- jQuery在前台接收后台json数组并处理
- 算法第四版 练习 1.3.39
- 畅通工程-并查集
- HTML标记和属性<完整版>
- 2017 杭电多校联赛第二场 1011 Regular polygon(多个点求正方形个数)POJ 2002
- 多线程---纯小白自己声明给自己的---勿喷
- java基础习题50道(四)
- python 字符和unicode之间的切换
- 写高质量OC代码52建议总结:48.多用块枚举,少用for循环
- Android开发 之 矢量图动画SVG(细节版)
- linux grep命令详解
- Mr.Smile填坑记——BaseRecyclerViewAdapterHelper使用时条目复用问题(各种状态混乱)
- 从MVC到前后端分离(REST-个人也认为是目前比较流行和比较好的方式)