Symmetry

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

 

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 ( 1N1, 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.

The following shows sample input and output for three test cases.

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

题意;在坐标系中给出的点中,寻找一个竖直的对称轴,让这些点关于它对称,如果它存在,输出YES,否则输出NO

看了很多人的博客,大多数此题用STL解决,了解它会更容易,但是我不太会,所以还是介绍的是一种自己好理解的避免出现精度问题的方法(坐标*2)

备注:

double类型进行运算会有精度误差.
比如
double a=1,b=1;
a-b可能不等于0,而是等于一个接近0的小数。所以我们认为只要a-b小于一个足够小的数(eps)的话,那么就可以认为a=b。

AC代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const double eps=1e-5;//1e-5:浮点数,在计算机中这么表示,在数学中是科学计数法.1e-5的意思就是1乘以10的负5次幂。就是0.000001

int x[1010],y[1010];
int main()
{
  int T;
  cin>>T;
  while(T--)
{
  int n,i,j;;
  cin>>n;

  double sum=0;

for(i=1; i<=n; i++)
{
  cin>>x[i]>>y[i];
  sum+=x[i];
}
  sum/=n;

for(i=1; i<=n; i++)
{
  for(j=1; j<=n; j++)
{
  if(abs(2*sum-x[i]-x[j])<eps&&abs(y[i]-y[j])<eps)   //这里相当于判断2*sum是否等于x[i]+y[j]且y[i]是否等于y[j]
               break;
}
  if(j>n) break;
}
  if(i>n)
cout<<"YES"<<endl;
  else
cout<<"NO"<<endl;
}
}

Symmetry(对称轴存在问题)的更多相关文章

  1. bzoj2592: [Usaco2012 Feb]Symmetry

    Description After taking a modern art class, Farmer John has become interested in finding geometric ...

  2. fzu 2035 Axial symmetry(枚举+几何)

    题目链接:fzu 2035 Axial symmetry 题目大意:给出n个点,表示n边形的n个顶点,判断该n边形是否为轴对称图形.(给出点按照图形的顺时针或逆时针给出. 解题思路:将相邻两个点的中点 ...

  3. [刷题]算法竞赛入门经典(第2版) 5-6/UVa1595 - Symmetry

    题意:平面上给若干点,问它们是不是关于某垂直于x轴的直线对称. 代码:(Wrong Answer, –ms) //UVa1595 - Symmetry #include<iostream> ...

  4. uvaoj-1595:symmetry

    1595 - Symmetry The figure shown on the left is left-right symmetric as it is possible to fold the s ...

  5. BZOJ 1100: [POI2007]对称轴osi

    1100: [POI2007]对称轴osi Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 630  Solved: 243[Submit][Statu ...

  6. 【BZOJ】1100: [POI2007]对称轴osi

    题意 给一个\(n(1 \le n \le 100000)\)个点不自交的多边形,求对称轴数目. 分析 将多边形表示成长度和角的形式(用有向面积来表示角也行),然后匹配. 题解 匹配可以用kmp或ma ...

  7. BZOJ1100 : [POI2007]对称轴osi

    将多边形转化为如下的环: 1到2的边,角2,2到3的边,角3,...,n-1到n的边,角n,n到1的边,角1 然后枚举对称轴,如果i是对称轴,那么[i-n,i+n]是一个回文串 用Manacher算法 ...

  8. UVa 1595 (水题) Symmetry

    颓废的一个下午,一直在切水题,(ˉ▽ ̄-) 首先如果这些点是对称的话,那么它们的对称轴就是x = m,m是横坐标的平均值. 把这些点放到一个集合里,然后扫描每个点,计算出它关于x = m的对称点,看这 ...

  9. uva 1595 - Symmetry

    思路:首先,如果这些点对称,那么它们的对称轴是x = m(m是所有点横坐标的平均值):   把这些点放到一个集合里,然后扫描每个点,计算出它关于x = m的对称点,看这个点是否在集合里面.   如果有 ...

随机推荐

  1. poj 1458 Common Subsequence【LCS】

    Common Subsequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43132   Accepted: 17 ...

  2. 第1章 Python基础之字符编码

    阅读目录 一.什么是字符编码 二.字符编码分类 三.字符编码转换关系 3.1 程序运行原理 3.2 终极揭秘 3.3 补充 总结 回到顶部 一.什么是字符编码 计算机要想工作必须通电,也就是说'电'驱 ...

  3. Dijkstra算法为什么权值不能为负

    Dijkstra算法当中将节点分为已求得最短路径的集合(记为S)和未确定最短路径的个集合(记为U),归入S集合的节点的最短路径及其长度不再变更,如果边上的权值允许为负值,那么有可能出现当与S内某点(记 ...

  4. DateTimePicker控件为空 分类: WinForm 2014-04-15 09:46 239人阅读 评论(0) 收藏

    设置属性:                 Format=Custom 加载事件:ValueChanged    private void dtpStart_ValueChanged(object s ...

  5. xcode设置项目图标玻璃镜效果

    xcode5中设置 ios6和ios7的适配一些小细节注意,ios6中图标会默认的设置玻璃镜效果 找到图片文件夹APPlcon中右侧设置中的有个iOS icon is pre-rend-rendere ...

  6. JavaBean的boolean isXXX反序列化问题

    JavaBean规范中规定boolean的getter/setter 为isXXX/setXXX,包装类Boolean的getter/setter 为getXXX/setXXX,其中XXX为变量名(I ...

  7. 基于RMAN的异机数据库克隆(rman duplicate)

    对于基于生产环境下的数据库的版本升级或者测试新的应用程序的性能及其影响,备份恢复等等,我们可以采取从生产环境以克隆的方式将其克隆到本地而不影响生产数据库的正常使用.实现这个功能我们可以借助rman d ...

  8. C#构造函数里的base和this的区别

    用法一: 父类的构造函数总是在子类之前执行的.既先初始化静态构造函数,后初始化子类构造函数. public class BaseCircle { public BaseCircle() { Conso ...

  9. NYOJ128前缀式计算

    前缀式计算 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 先说明一下什么是中缀式: 如2+(3+4)*5这种我们最常见的式子就是中缀式. 而把中缀式按运算顺序加上括 ...

  10. Android 环境下编译FFmpeg

    Android 环境下编译FFmpeg 开发环境:Ubuntu 12.04.2 LTS , android-sdk-linux, android-ndk-r8e 一 .X264 编译 1.    X2 ...