UVa 1595 (水题) Symmetry

颓废的一个下午,一直在切水题,(ˉ▽ ̄~)

首先如果这些点是对称的话,那么它们的对称轴就是x = m,m是横坐标的平均值。

把这些点放到一个集合里,然后扫描每个点,计算出它关于x = m的对称点,看这个点是否在集合里面。

如果有一个不在的话,说明不能构成对称图形。

 1 #include <cstdio>
 2 #include <algorithm>
 3 #include <set>
 4 using namespace std;
 5 
 6 struct Point
 7 {
 8     int x, y;
 9     Point(int x = 0, int y = 0):x(x), y(y) {}
10     bool operator < (const Point& rhs) const
11     { return x < rhs.x || (x == rhs.x && y < rhs.y); }
12 };
13 
14 const int maxn = 1000 + 10;
15 Point p[maxn];
16 
17 int main()
18 {
19     //freopen("in.txt", "r", stdin);
20 
21     int T, n;
22     scanf("%d", &T);
23     while(T--)
24     {
25         scanf("%d", &n);
26         set<Point> hehe;
27         double s = 0, m;
28         for(int i = 0; i < n; i++)
29         {
30             scanf("%d%d", &p[i].x, &p[i].y);
31             hehe.insert(p[i]);
32             s += p[i].x;
33         }
34         m = s / n;
35         bool ok = true;
36         for(int i = 0; i < n; i++)
37         {
38             Point t((int)(m*2)-p[i].x, p[i].y);
39             if(!hehe.count(t)) { ok = false; break; }
40         }
41         printf("%s
", ok ? "YES" : "NO");
42     }
43 
44     return 0;
45 }
代码君
原文地址:https://www.cnblogs.com/AOQNRMGYXLMV/p/4453951.html