uva1595对称轴 STL模拟
来源:互联网 发布:阿里云服务器视频教程 编辑:程序博客网 时间:2024/04/30 03:19
一开始zz了没想到用set存储和查找对称点……想了想这 是哪一章的习题……emmm
The figure shown on the left is left-right symmetric as it is possible to fold the sheet of paper along a
vertical line, drawn as a dashed line, and to cut the figure into two identical halves. The figure on the
right is not left-right symmetric as it is impossible to find such a vertical line.
Write a program that determines whether a figure, drawn with dots, is left-right symmetric or not.
The dots are all distinct.
Input
The input consists of T test cases. The number of test cases T is given in the first line of the input file.
The first line of each test case contains an integer N, where N (1 ≤ N ≤ 1, 000) is the number of dots
in a figure. Each of the following N lines contains the x-coordinate and y-coordinate of a dot. Both
x-coordinates and y-coordinates are integers between −10, 000 and 10, 000, both inclusive.
Output
Print exactly one line for each test case. The line should contain ‘YES’ if the figure is left-right symmetric,
and ‘NO’, otherwise.
Sample Input
3
5
-2 5
0 0
6 5
4 0
2 3
4
2 3
0 4
4 0
0 0
4
5 14
6 10
5 10
6 14
Sample Output
YES
NO
YES
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<set>using namespace std;struct point { double x, y; bool operator<(const point& rhs) const { return x - rhs.x < 0 || (x - rhs.x == 0 && y - rhs.y < 0); }};double mid;/*struct cmp { inline bool operator() (const point &a, const point &b) const { return a.x < b.x||a.x==b.x&&a.y<b.y; }};*/set<point> pe;int n,t;int readint() { int x; cin >> x;return x;}int main() { cin >> t; while (t--) { bool f = 1; int cnt = 0;//对称轴上的点 point e[1001]; n = readint(); mid=0; for (int i = 1; i <= n; i++) { e[i].x = readint(); e[i].y = readint(); pe.insert(e[i]); mid += e[i].x; } sort(e + 1, e + n + 1); mid /= n; for (int i = 1; i <= n; i++) { point p2; p2.x = mid * 2 - e[i].x; p2.y = e[i].y; if (!pe.count(p2) ) f = false; } if(f) printf("YES\n"); else printf("NO\n"); } //system("pause"); return 0;}
- uva1595对称轴 STL模拟
- UVA1595-对称轴
- UVA1595(对称轴)
- 习题5-6 对称轴 UVa1595
- 习题5-6 对称轴 UVA1595
- 习题5-6 对称轴(Symmetry, UVa1595)
- 关于"对称轴 (Symmetry, ACM/ICPC Seoul 2004, UVa1595"的讨论
- 算法竞赛入门经典 第二版 习题5-6 对称轴 Symmetry uva1595
- 算法竞赛入门经典(第2版)习题5-6 对称轴(Symmetry) Uva1595
- 对称轴
- UVa1595 - Symmetry
- UVa1595 - Symmetry
- [UVA1595]Symmetry
- UVa1595-Symmetry
- 对称轴(Symmetry)
- Super_Stack STL模拟栈
- hdu3347(模拟+STL)
- uva 11995 STL模拟
- linux下opencv无法正确读取avi视频文件
- 利用Tomcat catalina.policy实现禁止文件读写demo(window版)
- IT男装逼利器:如何像黑客一样聊天 Mojo-Webqq
- Batch Gradient Descent
- HOG算法的matlab实现1.0
- uva1595对称轴 STL模拟
- PAT
- 自定义View
- 专利:专利说明书的主要组成部分
- 合并二叉排序树
- Linux C编程 第13章进程间通信方式十个问题及解答(2)
- 数据结构与算法--栈与队列
- Concave and Convex Function
- 匿名内部类使用的外部变量为什么要是final的