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 ...
随机推荐
- [html] 回到页首
[转]本文来自:最简单最强大的插件框架(Net 2.0+) http://www.cnblogs.com/baihmpgy/p/3305215.html <!doctype html> & ...
- CentOs7安装gitlab(转!)
沧浪之水清兮,可以濯吾缨; 沧浪之水浊兮,可以濯吾足. ...
- Java常用的加密解密类(对称加密类)
Java常用的加密解密类 原文转载至:http://blog.csdn.net/wyc_cs/article/details/8793198 原创 2013年04月12日 14:33:35 1704 ...
- vs2013错误解决方法
1.cannot determine the location of the vs common tools folder 打开"VS2013开发人员命令提示后",上面提示&quo ...
- 解决“Can't bind to local 8630 for debugger”错误--查杀多余进程
Can't bind to local 8630 for debugger 表明本地8630端口被占用 1.Windows平台 在windows命令行窗口下执行: 1.查看所有的端口占用情况 C:\& ...
- xiao look 知识贴
从事中医临床近二十年了,多少总是积累了点经验,本来准备将来老了经验更丰富的时候传给子女的,可惜儿子根本不打算学医.在这个论坛里也混了不短了,感觉这里的风气很纯正,也有不少立志于中医的人士.为此,我决定 ...
- Python 实现双向链表(图解)
原文:https://blog.csdn.net/qq490691606/article/details/49948263 git 路径 https://github.com/wangpanjun/d ...
- Spark SQL 基本原理
Spark SQL 模块划分 Spark SQL架构--catalyst设计图 Spark SQL 运行架构 Hive的兼容性
- 目前学习的爬取小数据图片zzz
import os import threading import re import time from lxml import etree all_img_urls = [] # 图片列表页面的数 ...
- jieba库及wordcloud库的使用
知识内容: 1.jieba库的使用 2.wordcloud库的使用 参考资料: https://github.com/fxsjy/jieba https://blog.csdn.net/fontthr ...