uvaoj-1595:symmetry
1595 - Symmetry
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 ( 1N
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.
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
题解:刘汝佳白书135页练习题5.6;本题能够考虑暴力求解,也能够用set的查找来进行;
code:
#include <set>
#include <string>
using namespace std;
typedef pair<int,int> point;//定义类型;(不能够用预处理)
{
int cas;
int n;
int x,y;
cin>>cas;
while(cas--)
{
se.clear();
cin>>n;
int sum=0;
for(int i=0; i<n; i++)
{
cin>>x>>y;
sum+=x;//将全部横坐标加和;
se.insert(point(x*n,y));//(备注1)
}
/*
for(it=se.begin(); it!=se.end(); ++it)
{
point p=*it;
cout<<p.first<<" "<<p.second<<endl;
}
set<point> ::iterator it;
bool flag = true;
for(it=se.begin(); it!=se.end(); ++it)
{
point p=*it;
if(se.find(point(2*sum-p.first,p.second))==se.end())
{
flag=false;
break;
}
}
flag?
cout<<"YES"<<endl: cout<<"NO"<<endl;
}
return 0;
}
备注1:
x*n的意思,就是存储的时候将横坐标扩大n倍,由于对称轴肯定是竖线,所以如果对称的话全部的横坐标加和再与n想除得出的应该就是答案的x坐标;之所以不是将sum/n。是由于考虑到精度的问题。除的话会出现double类型;换而言之,这个存储方式就是将全部横坐标扩大了n倍;
uvaoj-1595:symmetry的更多相关文章
- 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)
We call a figure made of points is left-right symmetric as it is possible to fold the sheet of paper ...
- 【UVA】1595 Symmetry(模拟)
题目 题目 分析 理清思路,上模拟. 代码 #include <bits/stdc++.h> using namespace std; const int maxn=100 ...
- UVa 1595 Symmetry (set && math)
题意:给出n个在直角坐标系上的点,问你能不能找出一条竖轴(即垂直于x的轴)使得所有的点根据这条轴对称,能则输出YES,否则输出NO 分析:首先需要找到对称轴的值,将所有n个点的x轴的值加起来然后去除以 ...
- Uva 3226 Symmetry
题目给出一些点的坐标(横坐标,纵坐标),没有重叠的点,求是否存在一条竖线(平行于y轴的线),使线两边的点左右对称. 我的思路:对于相同的纵坐标的点,即y值相同的点,可以将x的总和计算出,然后除以点的数 ...
- UVa 1595 (水题) Symmetry
颓废的一个下午,一直在切水题,(ˉ▽ ̄-) 首先如果这些点是对称的话,那么它们的对称轴就是x = m,m是横坐标的平均值. 把这些点放到一个集合里,然后扫描每个点,计算出它关于x = m的对称点,看这 ...
- Symmetry UVA - 1595
The figure shown on the left is left-right symmetric as it is possible to fold the sheet of paper ...
- ACM/ICPC 之 数论-素数筛选法 与 "打表"思路(POJ 1595)
何为"打表"呢,说得简单点就是: 有时候与其重复运行同样的算法得出答案,还不如直接用算法把这组数据所有可能的答案都枚举出来存到一个足够大的容器中去-例如数组(打表),然后再输入数据 ...
随机推荐
- 今日SGU 5.20
SGU 404 题意:.. 收获:取模 #include<bits/stdc++.h> #define de(x) cout<<#x<<"="& ...
- MD5解密(常用语登录密码加密)
http://pmd5.com/
- 【Henu ACM Round#18 C】Ilya and Sticks
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用cnt[i]记录数字i出现的次数就好. 然后i从1e6逆序到1 如果cnt[i+1]和cnt[i]>0同时成立的话. 那么得 ...
- Mysql学习总结(8)——MySql基本查询、连接查询、子查询、正则表达查询讲解
查询数据指从数据库中获取所需要的数据.查询数据是数据库操作中最常用,也是最重要的操作.用户可以根据自己对数据的需求,使用不同的查询方式.通过不同的查询方式,可以获得不同的数据.MySQL中是使用SEL ...
- leetcode 数据库十题记录
题目从难到易记录.解题过程中,如果不太熟悉,可以将题目中的表自己手动录入到自己的数据库中,就方便学习,测试. 185. Department Top Three Salaries 要求就是查询出每个部 ...
- 使用python创建cocos2d-x项目
已准备条件: 已安装vs2012,已下载cocos2d-x sdk 2.2.3包. 旧版本号使用包里面的模板创建项目,如今新的包,使用python 来创建 1.下载安装 python https ...
- ethercat主站控制软件TwinCAT的安装
TwinCAT软件系统是基于PC兼容机的自己主动化系统,全称是"The Windows Control and Automation Technology".它把不论什么PC兼容机 ...
- sdut 2805(最小生成树)
大家快来A水题 Time Limit: 1000MS Memory limit: 65536K 题目描写叙述 (1<= N <=2000)(1<= M <= N*(N-1)/2 ...
- 项目: 更新(二) python 实现大概FTP的功能
服务器利用 socketserver 模块 构造, 实现了 多进程. 客户端仍然利用的是底层的 socket模块. 只不过进行了更深度的 解耦, 新加或者删除 某些功能 更方便 在上一个版本的基础上, ...
- POJ 2226 二分图最小覆盖
题意: 思路: 把横着的连通块放在一个集合 竖着的放在一个集合 如果有交 就连边 求最小覆盖即可 (数值上等于最大匹配) //By SiriusRen #include <cstdio> ...