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

题意

给你n个点,问是否可以找到一条竖线使得所有点对称

题解

首先去找竖线,竖线肯定在中间(注意竖线可以是小数),然后暴力所有点,查询对称点是否存在即可

代码

 #include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T,n,a,b;
cin>>T;
while(T--)
{
set<pi> se;
cin>>n;
int left=1e9,right=-1e9,F=;
for(int i=;i<n;i++)
{
cin>>a>>b;
if(left>a)
left=a;
if(right<a)
right=a;
se.insert(pi(a,b));
}
double mid=(left+right)*0.5;
pi ab;
for(auto ab:se)
{
a=(int)*mid-ab.first;
b=ab.second;
if(!se.count(pi(a,b)))
{
F=;
break;
}
}
if(F)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return ;
}

UVa 1595 Symmetry(set)的更多相关文章

  1. uva 1595 - Symmetry

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

  2. uva 1595 Symmetry“结构体”

    给出平面上N(N<=1000)个点.问是否可以找到一条竖线,使得所有点左右对称,如图所示: 则左边的图形有对称轴,右边没有.   Sample Input  3 5 -2 5 0 0 6 5 4 ...

  3. UVa 1595 Symmetry (set && math)

    题意:给出n个在直角坐标系上的点,问你能不能找出一条竖轴(即垂直于x的轴)使得所有的点根据这条轴对称,能则输出YES,否则输出NO 分析:首先需要找到对称轴的值,将所有n个点的x轴的值加起来然后去除以 ...

  4. UVa 1595 (水题) Symmetry

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

  5. 【UVA】1595 Symmetry(模拟)

    题目 题目     分析 理清思路,上模拟.     代码 #include <bits/stdc++.h> using namespace std; const int maxn=100 ...

  6. Symmetry UVA - 1595

      The figure shown on the left is left-right symmetric as it is possible to fold the sheet of paper ...

  7. Uva 3226 Symmetry

    题目给出一些点的坐标(横坐标,纵坐标),没有重叠的点,求是否存在一条竖线(平行于y轴的线),使线两边的点左右对称. 我的思路:对于相同的纵坐标的点,即y值相同的点,可以将x的总和计算出,然后除以点的数 ...

  8. UVa第五章STL应用 习题((解题报告))具体!

    例题5--9 数据库 Database UVa 1592 #include<iostream> #include<stdio.h> #include<string.h&g ...

  9. uvaoj-1595:symmetry

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

随机推荐

  1. linux&android PPP 相关知识

    Linux&Android PPP相关FAQ   目录 Linux&Android PPP相关FAQ.. 1 一.         文档说明... 3 二.         常见调试技 ...

  2. decorator的class方式

    class式的 Decorator decorator的class方式 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 clas ...

  3. 第10课 C++异常简介

    1. try-catch语句 (1)try语句处理正常代码逻辑 (2)catch语句处理异常情况 (3)try语句中的异常由对应的catch语句处理 (4)C++通过throw语句抛出异常信息 2. ...

  4. 长沙雅礼中学集训-------------------day1(内含day0)

    day0: 首先,请允许我吐槽一下: 1.那些一个人住一个标准房的人您们真的是#@**¥&%……#*()%……*()@Q$&. 2.感谢那些一个人住一个标准间的人,要不然我们也找不到这 ...

  5. php 编程笔记分享

    php获取POST数据的三种方法php 图片加水印源代码php+ajax+json的一个最简单实例php 汉字转拼音源码php遍历目录,生成目录下每个文件的md5值并写入到结果文件中php实现linu ...

  6. Petapoco 查询 语法

    查询语句 Sql sql = Sql.Builder; sql.Select("spb_MailAddress.*") .From("spb_MailAddress&qu ...

  7. zabbix 监控数据库 及 tcp连接数

    参考网站: 监控sqlserver      http://blog.51cto.com/13272050/2050601 http://blog.51cto.com/ultrasql/1927672 ...

  8. xe7 控件升级

    rm.ehlib.synedit OK SynSQLSyn1->TableNames 为NULL,导致添加数据失败,XE6正常 放在按钮里也不正常,就不说初始化次序引起的.

  9. Activity服务类-8 RuntimeService服务类

    一共89个接口1.启动流程实例(20个方法)//使用给定的键在流程定义的最新版本中启动一个新的流程实例.ProcessInstance startProcessInstanceByKey(String ...

  10. 前端-CSS-11-Z-index

    ---- z-index 这个东西非常简单,它有四大特性,每个特性你记住了,页面布局就不会出现找不到盒子的情况. z-index 值表示谁压着谁,数值大的压盖住数值小的, 只有定位了的元素,才能有z- ...