Regular polygon(HDU 6055)
来源:互联网 发布:好听的网络名字 编辑:程序博客网 时间:2024/05/16 05:49
Regular polygon
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 138 Accepted Submission(s): 52
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
Source
2017 Multi-University Training Contest - Team 2
//题意:二维平面上给N个整数点,问能构成几个不同的正多边形。
//思路:这种正多边形只能是正四边形,即正方形(因为给的位置点的坐标都是整数,其他多边形不可能每条边都相同,好像有论文证明的QAQ)。这样问题就简化了很多。
把这几种情况考虑全就行,注意菱形不是正4变形...因为这个WA了无数发...,这题应该是team2最水的题之一了,然而WA了20发...20发...
还有一点就是坐标是可能为负的(但>= -100),所以用 map[][]去存的时候要点的坐标+105,不然map[][]这2个[][]里的数字会是负的,会RE...
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cmath>#include <queue>#include <algorithm>using namespace std;const int MAX = 600;const int INF = -1e9;typedef struct {int x, y;}Point;int n;long long sum;int map[3000][3000];int maxx, maxy;Point point[MAX];bool cmp(Point a, Point b){if (a.y == b.y)return a.x < b.x;return a.y < b.y;}void find(){int i, j, k;for (i = 0; i < n; i++){if (point[i].x == maxx || point[i].y == maxy)continue;for (j = i + 1; j < n; j++){if (point[j].x <= point[i].x)continue;if (point[j].y <= point[i].y)continue;int len = point[j].x - point[i].x;int leny = point[j].y - point[i].y;if (map[point[i].x + len + 105][point[i].y + leny + 105] == 1 && map[point[i].x + leny + 105][point[i].y - len + 105] == 1 && map[point[i].x + len + leny + 105][point[i].y + leny - len + 105] == 1){sum++;}if (point[j].y == point[i].y + len){if (map[point[i].x + len + 105][point[i].y + 105] == 1 && map[point[i].x + 105][point[i].y + len + 105] == 1 && map[point[i].x + len + 105][point[i].y + len + 105] == 1){sum++;}}}}}int main(){while (scanf("%d", &n) != EOF){sum = 0;maxx = INF;maxy = INF;memset(map, 0, sizeof(map));for (int i = 0; i < n; i++){scanf("%d%d", &point[i].x, &point[i].y);int x = point[i].x + 105;int y = point[i].y + 105;map[x][y] = 1;if (point[i].x > maxx)maxx = point[i].x;if (point[i].y > maxy)maxy = point[i].y;}sort(point, point + n, cmp);find();printf("%lld\n", sum);}return 0;}
阅读全文
2 0
- Regular polygon(HDU 6055)
- [HDU]-6055 Regular polygon
- hdu-6055-Regular polygon
- Regular polygon HDU 6055
- hdu--6055--Regular polygon
- HDU 6055 Regular polygon
- hdu 6055 Regular polygon
- hdu 6055 Regular polygon
- HDU 6055 Regular polygon
- hdu 6055 Regular polygon
- hdu 6055 Regular polygon
- HDU 6055 Regular polygon
- HDU 6055 Regular polygon
- HDU 6055 Regular polygon
- HDU-6055 Regular polygon
- HDU-6055-Regular polygon
- HDU 6055 Regular polygon (找正方形)
- HDU 6055 Regular polygon(几何)
- ANDROID SDK 源码解析
- 算法竞赛入门经典-刘汝佳-第七章暴力
- hpuoj 【1213】做道水题冷静一下 【sort】
- ## Lee的小白笔记————Material Design 之 Toolbar ##
- C/C++ | 23-13 求此数列前20项的和
- Regular polygon(HDU 6055)
- 第 7 章 图
- matlab interp2函数详解
- python基础知识整理
- 《开发Microsoft Visio解决方案》学习总结
- UICollectionView、UICollectionReusableView头视图重叠问题
- C/C++ | 24-14 间隔删数组,求最后一个被删掉的数的原始下标位置
- Python3 Linux 安装
- Unity中AssetBundle的打包和加载