Symmetry
来源:互联网 发布:练毛笔字的软件 编辑:程序博客网 时间:2024/04/30 06:12
【题目描述】
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.
【输入格式】
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
【输出格式】
Print exactly one line for each test case. The line should contain ‘YES’ if the figure is left-right symmetric. and `NO’, otherwise.
The following shows sample input and output for three test cases.
【样例输入】
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
【样例输出】
YES
NO
YES
【分析】
容易想到,如果存在对称轴,那么对称轴的横坐标一定是最左边的点和最右边的点的中点。为了避免中点是小数 可以将横坐标都乘上2,然后在判断所有点是否有对称点就行了。
var x,y:array[0..1001]of longint; left,right,i,n,mid,t:longint; flag:boolean;function check(k:longint):boolean;var i:longint;begin for i:=1 to n do if (y[i]=y[k])and(x[i]+x[k]=2*mid) then exit(true); exit(false);end;begin readln(t); while t>0 do begin dec(t); left:=1;right:=1; readln(n); for i:=1 to n do begin readln(x[i],y[i]); x[i]:=x[i]*2; if x[i]<x[left] then left:=i; if x[i]>x[right] then right:=i; end; mid:=(x[left]+x[right]) div 2; flag:=true; for i:=1 to n do if not check(i) then flag:=false; if flag then writeln('YES') else writeln('NO'); end;end.
- Symmetry
- Symmetry
- UVa1595 - Symmetry
- 1595 - Symmetry
- 对称轴(Symmetry)
- UVa1595 - Symmetry
- [UVA1595]Symmetry
- UVA_1595: Symmetry
- UVa1595-Symmetry
- rotational symmetry
- Symmetry UVA
- Symmetry CSU
- bzoj2592 Symmetry
- Symmetry UVA
- Centre of symmetry
- [1_6_checker] Bitmarks & Symmetry
- CodeForces 201A Symmetry
- UVa 1595 Symmetry
- java系统高并发解决方案(综合转载)
- keil gcc如何重定向pritnf函数,并将调试信息输出到keil的debug viewer
- 面试算法高频题:给定N个数的间距最大值
- oracle触发器学习
- 关于ugui布局(含scrollview)
- Symmetry
- 记“平庸”
- 敬请期待……
- MediaPlayer类详解
- JAVA 学习模块九: static(静态)关键字
- 技术面知识点总结
- UCASE() 函数
- 在编程的边缘蹦跶
- 敬请期待……