UVa 1595 Symmetry(set)
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)的更多相关文章
- uva 1595 - Symmetry
思路:首先,如果这些点对称,那么它们的对称轴是x = m(m是所有点横坐标的平均值): 把这些点放到一个集合里,然后扫描每个点,计算出它关于x = m的对称点,看这个点是否在集合里面. 如果有 ...
- uva 1595 Symmetry“结构体”
给出平面上N(N<=1000)个点.问是否可以找到一条竖线,使得所有点左右对称,如图所示: 则左边的图形有对称轴,右边没有. Sample Input 3 5 -2 5 0 0 6 5 4 ...
- UVa 1595 Symmetry (set && math)
题意:给出n个在直角坐标系上的点,问你能不能找出一条竖轴(即垂直于x的轴)使得所有的点根据这条轴对称,能则输出YES,否则输出NO 分析:首先需要找到对称轴的值,将所有n个点的x轴的值加起来然后去除以 ...
- UVa 1595 (水题) Symmetry
颓废的一个下午,一直在切水题,(ˉ▽ ̄-) 首先如果这些点是对称的话,那么它们的对称轴就是x = m,m是横坐标的平均值. 把这些点放到一个集合里,然后扫描每个点,计算出它关于x = m的对称点,看这 ...
- 【UVA】1595 Symmetry(模拟)
题目 题目 分析 理清思路,上模拟. 代码 #include <bits/stdc++.h> using namespace std; const int maxn=100 ...
- Symmetry UVA - 1595
The figure shown on the left is left-right symmetric as it is possible to fold the sheet of paper ...
- Uva 3226 Symmetry
题目给出一些点的坐标(横坐标,纵坐标),没有重叠的点,求是否存在一条竖线(平行于y轴的线),使线两边的点左右对称. 我的思路:对于相同的纵坐标的点,即y值相同的点,可以将x的总和计算出,然后除以点的数 ...
- UVa第五章STL应用 习题((解题报告))具体!
例题5--9 数据库 Database UVa 1592 #include<iostream> #include<stdio.h> #include<string.h&g ...
- uvaoj-1595:symmetry
1595 - Symmetry The figure shown on the left is left-right symmetric as it is possible to fold the s ...
随机推荐
- 除了用作缓存数据,Redis还可以做这些
Redis应该说是目前最受欢迎的NoSQL数据库之一了.Redis通常被作为缓存组件,用作缓存数据.不过,除了可以缓存数据,其实Redis可以做的事还有很多.下面列举几例,供大家参考. 1.最新列表 ...
- appium 5-27屏幕旋转、
1.屏幕切换 注意:应用一定要支持横竖屏切换,否则无效果, public void testBrowser() throws InterruptedException { Thread.sleep(1 ...
- 在win7/WINDOWS SERVER 2008 R2上安装 vmware POWERcli 6.5
安装.NET Framework 4.6.2下载NDP462-KB3151800-x86-x64-AllOS-ENU.exe,安装安装PowerShell 4.0(5.0依赖4.0)下载Windows ...
- Vue引用其他组件,但组件某些部分不需要时的简单处理
项目开发时,我们会把多个地方重复使用的模块抽象成组件,提供给大家一起使用,但是使用组件的时候偶尔会遇见一些问题,比如说组件里只有某些东西自己并不需要,这个时候我们可以对组件进行简单的修改,而不影响其他 ...
- 防火墙没有关导致外部访问虚拟机的tomcat遇到的问题和解决方法
部署好tomcat,想在自己电脑上的浏览器访问,但是发现访问不了 访问方式是浏览器地址栏输入ip加端口,我的是192.138.211.121:8080,显示结果是无连接 在电脑上ping一下主机发现是 ...
- php中的释放语句unset和释放函数mysql_free_result()
首先要强调的一点是unset在php中已经不再是一个函数了,既然不是函数,那么就没有了返回值,所以用的时候不能够用unset的返回值来做判断. 其次,在函数中,unset只能销毁局部变量,并不能销毁全 ...
- SignalR + Mvc 4 web 应用程序
在上节中,我们已经初步对 SignalR 进行了了解,这一节我们将做一个SignalR Demon,具体的步骤如下: 1. 创建一个 mvc 4 web 应用程序,并选择 Basic 2. 创建一个 ...
- Java的this和super总结
内容: 1.this和super作用 2.继承关系图 1.this和super作用 this和super的作用: this:区分本类中的成员变量和局部变量同名的情况,代指本类 super:区分子类中的 ...
- Python之模块(二)
1.subprocess模块 2.loggin模块 很多程序都有记录日志的需求,并且日志中包含的信息即有正常的程序访问日志,还可能有错误.警告等信息输出,python的logging模块提供了标准的日 ...
- SourceTree使用方法
一 .SourceTree简介 SourceTree 是 Windows 和Mac OS X 下免费的 Git 和 Hg 客户端,拥有可视化界面,容易上手操作.同时它也是Mercurial和Subve ...