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\n", ok ? "YES" : "NO");
42     }
43
44     return 0;
45 }

代码君

时间: 2024-08-01 04:25:43

UVa 1595 (水题) Symmetry的相关文章

UVa 10391 (水题 STL) Compound Words

今天下午略感无聊啊,切点水题打发打发时间,=_=|| 把所有字符串插入到一个set中去,然后对于每个字符串S,枚举所有可能的拆分组合S = A + B,看看A和B是否都在set中,是的话说明S就是一个复合词. 1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 #include <cstring> 5 #include <string> 6 #include <

UVa 400 (水题) Unix ls

题意: 有n个文件名,排序后按列优先左对齐输出.设最长的文件名的长度为M,则最后一列长度为M,其他列长度为M+2. 分析: 这道题很简单,但要把代码写的精炼,还是要好好考虑一下的.lrj的代码中有两个亮点,一个是print子函数,一个就是行数的计算.用心体会 1 #include <iostream> 2 #include <cstdio> 3 #include <string> 4 #include <algorithm> 5 using namespac

UVa 11040 (水题) Add bricks in the wall

题意: 45块石头如图排列,每块石头上的数等于下面支撑它的两数之和,求其余未表示的数. 分析: 首先来计算最下面一行的数,A71 = A81 + A82 = A91 + 2A92 + A93,变形得到A92 = (A71 - A91 - A93) / 2. 以此类推,就能得到最下面一整行的数.有了这个“地基”以后,所有的数就都能算出来了. 1 #include <cstdio> 2 3 int a[10][10]; 4 5 int main() 6 { 7 //freopen("in

UVa 1593 (水题 STL) Alignment of Code

话说STL的I/O流用的还真不多,就着这道题熟练一下. 用了两个新函数: cout << std::setw(width[j]);    这个是设置输出宽度的,但是默认是在右侧补充空格 所以就要用cout.setf(ios::left);来设置一下左对齐. 1 #include <iostream> 2 #include <cstdio> 3 #include <sstream> 4 #include <vector> 5 #include &l

UVa 10935 (水题) Throwing cards away I

直接用STL里的queue模拟即可. 1 #include <cstdio> 2 #include <queue> 3 using namespace std; 4 5 const int maxn = 60; 6 int discarded[maxn], cnt; 7 8 int main() 9 { 10 int n; 11 while(scanf("%d", &n) == 1 && n) 12 { 13 cnt = 0; 14 qu

uva 1368 水题

枚举每一列的位置,求哪个字符出现的次数最多 #include<iostream> #include<string> #include<map> #include<cstdio> #include<vector> #include<algorithm> #include<assert.h> #include<cstring> using namespace std; #define _for(i, a, b) f

UVa 1586 Molar mass --- 水题

UVa 1586 题目大意:给出一种物质的分子式(不带括号),求分子量.本题中分子式只包含4种原子,分别为C.H.O.N, 原子量分别为12.01,1.008,16.00,14.01 解题思路:先实现一个从字符型的数到整型的数的转换函数,再将输入的串从头到尾扫描,遇到字母,则进一步扫描后面的数字的区间, 再调用函数进行转换,再乘以其的原子质量,最后累加到sum中即可. /* UVa 1586 Molar mass --- 水题 */ #include <cstdio> #include <

UVa 272 Tex Quotes --- 水题

题目大意:在TeX中,左引号是 ``,右引号是 ''.输入一篇包含双引号的文章,你的任务是把他转成TeX的格式 解题思路:水题,定义一个变量标记是左引号还是右引号即可 /* UVa 272 Tex Quotes --- 水题 */ #include <cstdio> #include <cstring> int main() { #ifdef _LOCAL freopen("D:\\input.txt", "r", stdin); #endi

UVa 1584 Circular Sequence --- 水题

UVa 1584 题目大意:给定一个含有n个字母的环状字符串,可从任意位置开始按顺时针读取n个字母,输出其中字典序最小的结果 解题思路:先利用模运算实现一个判定给定一个环状的串以及两个首字母位置,比较二者字典序大小的函数, 然后再用一层循环,进行n次比较,保存最小的字典序的串的首字母位置,再利用模运算输出即可 /* UVa 1584 Circular Sequence --- 水题 */ #include <cstdio> #include <cstring> //字符串s为环状,