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 ...
随机推荐
- rsync同步配置
因为公司数据库比较重要,现在只有一台服务器,IP为:118.145.*.*暂称为server,公司一台虚拟机,IP为.192.168.0.100 ,暂称为rsync 1.安装服务器端:yum -y i ...
- Unity3D添加Admob广告
重要提示: 貌似play2014年8月之后不会再支持admob的SDK方式的广告了.github上已经有了 Unity AdMob (Google Play Services) ...
- MLlib 卡方检验
1.卡方检验理论 1.1. 简介 总体的分布函数完全未知或只知形式.但不知其参数的情况,为了推断总体的某些未知特性,提出某些关于总体的假设.我们要根据样本对所提出的假设作出是接受,还是拒绝的决策.假 ...
- SQL viewId 比较好看的 Id
有时候我们希望 Id 要好看一些,比如 Id=1 -> Id=T000001 refer : http://www.kodyaz.com/t-sql/custom-sequence-string ...
- Android中日志工具的使用
添加LogCat到你的Eclipse日志在任何项目的开发过程中都会起到非常重要的作用,在Android项目中如果你想要查看日志则必须要使用LogCat工具.当你第一次在Eclipse中运行Androi ...
- Kcptun 是一个非常简单和快速的,基于KCP 协议的UDP 隧道,它可以将TCP 流转换为KCP+UDP 流
本博客曾经发布了通过 Finalspeed 加速 Shadowsocks 的教程,大家普遍反映能达到一个非常不错的速度.Finalspeed 虽好,就是内存占用稍高,不适合服务器内存本来就小的用户:而 ...
- hibernate 映射<三>一对一外键键关联
bean 关系: 正向工程: 反向工程: 逆向生成步骤: 生成的xml: ... from hbm_one2one_pk.person person0_ left outer join hbm_one ...
- 【转】Thunderbird on Ubuntu 12.04 – 调整邮件列表行间距
原文网址:http://www.xuebuyuan.com/414703.html markz@markz-hp6200:~$ cd .thunderbird/ markz@markz-hp6200: ...
- HDU_1042——阶乘,万进制
#include <cstdio> ; const int BASE = MAX; int main() { int n, i, j; while(~scanf("%d" ...
- 如何在Windows服务程序中读写HKEY_CURRENT_USER注册表
在服务程序中想要对注册表HKEY_CURRENT_USER下的内容进行读写,不会返回失败,但是始终无效.原因是: 1.服务运行在系统权限之下,而不是任何一个用户 2.HKEY_CURRENT_USER ...