中南大学第十一届大学生程序设计竞赛-COJ1896-Symmetry
2017-04-24 20:57
411 查看
1896: Symmetry
Submit Page Summary Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 2 Solved: 2Description
We call a figure made of points is left-right symmetric as it is possible to fold the sheet of paper along a vertical line and to cut the figure into two identical halves.For example, if a figure exists five points, which respectively are (-2,5),(0,0),(2,3),(4,0),(6,5). Then we can find a vertical line x = 2 to satisfy this condition. But in another figure which are (0,0),(2,0),(2,2),(4,2), we can not find a vertical line to make this figure left-right symmetric.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
Hint
Source
中南大学第十一届大学生程序设计竞赛
题目大意:给定二维平面上的n个点,判断这n个点是否左右对称,不需要考虑旋转对称的情况。
解题思路:先确定图的对称轴,将点分别从左到右和从右到左排序,检查对应位置上的点是否对称即可。
考查内容:排序函数的使用
时间复杂度: O(nlogn)
题目难度:★★
#include<iostream> #include<algorithm> using namespace std; struct node { int x,y; }a[1005],b[1005]; bool cmp1(node u,node v) { return u.x==v.x?u.y<v.y:u.x<v.x; } bool cmp2(node u,node v) { return u.x==v.x?u.y<v.y:u.x>v.x; } int main() { ios::sync_with_stdio(false); int T; cin>>T; while(T--) { int n; cin>>n; for(int i=1;i<=n;i++) { cin>>a[i].x>>a[i].y; b[i].x=a[i].x; b[i].y=a[i].y; } sort(a+1,a+n+1,cmp1); sort(b+1,b+n+1,cmp2); int sym=a[1].x+b[1].x; bool flag=true; for(int i=1;i<=n;i++) { if(a[i].x+b[i].x!=sym||a[i].y!=b[i].y) { flag=false; break; } } if(flag) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
相关文章推荐
- 中南大学第十一届大学生程序设计竞赛-COJ1895-Apache is late again
- 中南大学第十一届大学生程序设计竞赛-COJ1901-赏赐 OR 灾难
- 中南大学第十一届大学生程序设计竞赛网络预选赛总结
- 中南大学第十一届大学生程序设计竞赛-COJ1900-锋芒不露
- 中南大学第十一届大学生程序设计竞赛-COJ1897-The price table of the snack store
- 中南大学第十一届大学生程序设计竞赛-COJ1899-Yuelu Scenes
- 中南大学第十一届大学生程序设计竞赛-COJ1904-精灵的交际网
- 中南大学第十一届大学生程序设计竞赛-COJ1902-Happy Chinese Poker
- 中南大学第十一届大学生程序设计竞赛-COJ1903-Tricky数
- 中南大学第十一届大学生程序设计竞赛总结
- 中南大学第十一届大学生程序设计竞赛-COJ1898-复盘拉火车
- HNNU 11658 阶乘除法【湖南省第十一届大学生计算机程序设计竞赛,数论】
- 河南省第十一届ACM大学生程序设计竞赛
- 第十一届东北地区大学生程序设计竞赛赛后感想
- HNNU 11662 又一道简单题【湖南省第十一届大学生计算机程序设计竞赛,模拟,暴力】
- CSU Problem 1777 大还是小?——湖南省第十一届大学生计算机程序设计竞赛
- 湖南省第十一届大学生计算机程序设计竞赛—错误的算法
- CSU Problem 1785 又一道简单题——湖南省第十一届大学生计算机程序设计竞赛
- 20140425 虚拟赛 中南大学第八届大学生程序设计竞赛
- 中南大学第九届大学生程序设计竞赛网络预选赛