您的位置:首页 > 编程语言 > Go语言

Regular polygon - HDU 6055 - 2017 多校

2017-07-28 01:23 483 查看

题目:

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


题意:

  给你一些点的坐标,坐标均为整数,让你求这些点可以构成多少个正多边形。

思路:

  因为所有点的坐标均为整数,所以唯一可以构成的正多边形就只有正方形,于是这道题就转化成这些点可以构成多少个正方形的问题,在这里运用到了弦图的知识,就是平面里任意两点和其所能构成的正方形的余下两点的关系。

实现:

#include <bits/stdc++.h>
using namespace std;
map<pair<int,int>,bool> mp;
int x[1007],y[1007],n,ans;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
while(mp.clear(),ans = 0,cin >> n) {
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
mp[make_pair(x[i], y[i])] = 1;

}
for(int i=0 ; i<n ; i++)
for(int j=0 ; j<i ; j++) {
//弦图
int dx = y[j] - y[i], dy = x[i] - x[j], cnt = 0;
if (bool(mp.count(make_pair(x[i] + dx, y[i] + dy)))) cnt++;
if (bool(mp.count(make_pair(x[j] + dx, y[j] + dy)))) cnt++;
if (cnt == 2) ans++;
cnt = 0;
if (bool(mp.count(make_pair(x[i] - dx, y[i] - dy)))) cnt++;
if (bool(mp.count(make_pair(x[j] - dx, y[j] - dy)))) cnt++;
if (cnt == 2) ans++;
}
cout << ans/4 << '\n';
}
return 0;
}


其他:

  这个题我找教练要了数据,结果在本地全部通过,交上去WA了,于是从20点整开始一直各种调试各种debug到0点,整整花了四个小时。到最后发现是因为使用了
ios_base::sync_with_stdio(false);
之后,我又将流输入输出和
scanf()
printf()
混用,导致OJ评测不正确。

  另外,在判断正方形点是否存在部分,我原本的写法是
if (mp[make_pair(x[i] + dx, y[i] + dy)]) cnt++;
可发现这样写的话
TLE
,试了一下
count
函数,结果过了。

  附上一个测试样例点:

Input

200
-12 -93
34 -78
-37 92
16 -45
1 -55
74 43
22 4
-66 28
24 87
82 70
-23 23
-13 -30
51 -72
-42 -61
-14 -64
-64 67
30 56
-35 -21
-6 26
3 -10
-66 31
-5 55
-91 -80
-16 -75
52 -81
57 58
-97 -53
79 -29
-49 -62
-34 -27
35 -52
84 37
4 55
72 83
-55 -32
33 14
-19 26
-69 -41
-28 -34
37 70
-29 -75
-27 -36
48 -25
90 27
39 -88
86 -4
-26 -41
-14 81
57 -18
28 22
24 -64
63 -67
-20 -38
-62 -47
-20 12
-20 37
-29 -10
-38 -46
-24 58
31 53
84 3
-16 36
-33 -30
-33 -28
63 72
4000

-74 44
-9 -31
-2 -25
-14 -13
-51 -29
38 -22
-6 -30
34 11
61 -30
-45 -13
-89 39
-5 75
-25 2
76 3
-38 -81
53 -52
93 51
69 -74
63 -2
12 -25
17 94
82 -28
40 47
-93 15
-18 -57
14 6
23 -54
-37 0
-62 -41
-39 44
5 -32
-5 36
-27 -29
61 -18
80 42
-32 58
-16 63
27 48
50 9
85 25
25 -22
12 62
-28 32
51 1
14 -30
-54 -32
58 24
56 33
-34 -71
11 -65
40 30
80 83
-76 78
86 10
53 3
14 -3
-27 -26
-23 -80
-35 15
87 5
-44 20
32 -35
50 -52
72 -9
-52 -22
38 -61
3 24
32 2
61 62
-24 -15
-86 -74
-86 64
15 59
-14 -60
-45 -32
-34 -32
78 1
40 27
43 -75
46 -84
-8 -13
-86 100
78 -69
42 -67
20 -57
23 20
55 -96
-15 6
59 -43
-3 49
43 3
59 10
89 -75
17 6
-72 -58
32 -7
-72 -66
-62 -63
50 -93
3 34
40 65
-30 -10
3 55
52 -34
98 -39
32 9
-23 -54
-98 11
-10 55
-59 26
82 59
-56 -56
22 -18
-48 18
-11 -25
37 -22
47 21
-84 -42
-30 -12
-10 -8
62 -9
-2 33
-34 -60
1 20
-46 -90
67 59
-81 -91
-38 17
-52 -3
-24 -10
87 -81
20 60
-34 -57
-51 -95
38 -43


Output

6
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐