hdu6055 17多校二1011 Regular polygon
来源:互联网 发布:数据科学入门 编辑:程序博客网 时间:2024/06/08 12:19
读题的题目
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.
一直在想怎么去求多边形的个数
如果是整数点的话
能构成的正多边形只能是正方形
在一堆点里求正方形个数是老题目
比如poj2002
#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; }
阅读全文
0 0
- hdu6055 17多校二1011 Regular polygon
- HDU6055 Regular polygon【哈希】
- HDU6055-Regular polygon
- HDU6055(Regular polygon)
- HDU6055-Regular polygon
- hdu6055--Regular polygon
- HDU6055 Regular polygon(思路)
- HDU6055-Regular polygon 简单平面几何
- 2017多校训练Contest2: 1011 Regular polygon hdu6055
- hdu6055 Regular polygon【思维+几何基础】
- hdu6055 Regular polygon(简单计算几何)
- HDU6055 Regular polygon +多校联赛第二场
- Hdu6055 Regular polygon(2017多校第2场)
- HDU6055 Regular polygon(2017多校第二场)
- HDU6055 Regular polygon 2017 Multi-University Training Contest
- hdu6055—Regular polygon(正方形的判定)
- 2017杭电多校联赛第二场-Regular polygon (hdu6055)判断点集能构成多少个正方形
- HDU6055 Regular polygon(计算几何,2017 HDU多校联赛 第2场)
- Kotlin Reference (二) Idioms
- c++static关键字
- 高级装配 —— 如何处理自动装配的歧义性?
- 键盘事件和鼠标事件
- [zicreate]Altium Designer 15原理图与PCB设计视频课程
- hdu6055 17多校二1011 Regular polygon
- npm install 报NO REPOSITORY FIELDS No README data
- CodeForces830B【树状数组+线段树】
- 1149: 组合三位数之二
- 图的深度优先遍历(DFS)和广度优先遍历(BFS)
- ccf认证分蛋糕java代码
- 说明
- Unity_UML图的使用02_035
- mysql的批量插入