uva 1595 - Symmetry
思路:首先,如果这些点对称,那么它们的对称轴是x = m(m是所有点横坐标的平均值);
把这些点放到一个集合里,然后扫描每个点,计算出它关于x = m的对称点,看这个点是否在集合里面。
如果有一个不在的话,说明不能构成对称图形。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <set>
using namespace std; struct Point{
int x, y;
Point(int x = , int y = ):x(x), y(y){}
bool operator < (const Point & rhs) const
{
return x < rhs.x || (x == rhs.x && y < rhs.y);
}
}; const int maxn = + ;
Point p[maxn]; int main()
{
int T, n;
set<Point> sP;
scanf("%d", &T);
while(T--)
{
double s = , m;
sP.clear();
scanf("%d", &n);
for(int i = ; i < n; i++)
{
cin >> p[i].x >> p[i].y;
sP.insert(p[i]);
s += p[i].x;
}
m = s / n; // m: must to be a integer.
bool ok = true;
for(int i = ; i < n; i++)
{
Point t((int)(m*)-p[i].x, p[i].y);
if(!sP.count(t))
{
ok = false;
break;
}
}
printf("%s\n", ok ? "YES" : "NO");
}
return ;
}
uva 1595 - Symmetry的更多相关文章
- 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 (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 ...
随机推荐
- Windows 7 Apache下计算机无法访问局域网网站的问题
在Windows 7系统下,由于安全限制问题,本机搭建的网站,局域网内其它计算机是无法访问的. 要解决这个问题,只需要在防火墙加入自建规则便可以了,具体步骤如下: 控制面板=>Windows防火 ...
- asp.net2.0app开发。
asp.net app 网站开发:http://www.cnblogs.com/TerryFeng/archive/2009/05/15/1457731.html 在OPERA或M3GATE中设置编码 ...
- 转:MFC创建多线程实例
作者:http://blog.csdn.net/wangningyu/article/details/4404134 平时在MFC里使用多线程时其实是很方面的,因为微软提供了一个API让我们很方面的去 ...
- ng-class的使用
例如: td(ng-class="{0:'text-warning',1:'text-primary'}[bj.flag]") {{bj.flag | bjFlagfilter}} ...
- ural 1613 For Fans of Statistics
#include <cstdio> #include <cstring> #include <map> #include <vector> #inclu ...
- Yii数据库
http://www.yiiframework.com/doc/guide/1.1/zh_cn/database.ar http://zhengdl126.iteye.com/blog/1460779 ...
- 【HDOJ】1520 Anniversary party
第二道树形DP,先是MLE.后来仅需改小邻接矩阵的第二个维度到30就过了. #include <cstdio> #include <cstring> #include < ...
- Qt入门(6)——Qt的界面布局
Qt提供四种布局: VBoxLayout:垂直布局 HBoxLayout:水平布局 GridLayout:二维布局. FormLayout: 窗体布局
- linux 信号signal和sigaction理解
今天看到unp时发现之前对signal到理解实在浅显,今天拿来单独学习讨论下. signal,此函数相对简单一些,给定一个信号,给出信号处理函数则可,当然,函数简单,其功能也相对简单许多,简单给出个函 ...
- 转载:SQL Server高效 -- 设计(ITPUT 讨论汇总
http://blog.csdn.net/zjcxc/article/details/8979756 认为在设计SQL Server对象时,主要会考虑哪些因素来避免出现性能问题? 讨论汇总——总体设计 ...