颓废的一个下午,一直在切水题,(ˉ▽ ̄~)

首先如果这些点是对称的话,那么它们的对称轴就是x = m,m是横坐标的平均值。

把这些点放到一个集合里,然后扫描每个点,计算出它关于x = m的对称点,看这个点是否在集合里面。

如果有一个不在的话,说明不能构成对称图形。

 #include <cstdio>
#include <algorithm>
#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()
{
//freopen("in.txt", "r", stdin); int T, n;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
set<Point> hehe;
double s = , m;
for(int i = ; i < n; i++)
{
scanf("%d%d", &p[i].x, &p[i].y);
hehe.insert(p[i]);
s += p[i].x;
}
m = s / n;
bool ok = true;
for(int i = ; i < n; i++)
{
Point t((int)(m*)-p[i].x, p[i].y);
if(!hehe.count(t)) { ok = false; break; }
}
printf("%s\n", ok ? "YES" : "NO");
} return ;
}

代码君

UVa 1595 (水题) Symmetry的更多相关文章

  1. UVa 10391 (水题 STL) Compound Words

    今天下午略感无聊啊,切点水题打发打发时间,=_=|| 把所有字符串插入到一个set中去,然后对于每个字符串S,枚举所有可能的拆分组合S = A + B,看看A和B是否都在set中,是的话说明S就是一个 ...

  2. UVa 10935 (水题) Throwing cards away I

    直接用STL里的queue模拟即可. #include <cstdio> #include <queue> using namespace std; ; int discard ...

  3. UVa 1593 (水题 STL) Alignment of Code

    话说STL的I/O流用的还真不多,就着这道题熟练一下. 用了两个新函数: cout << std::setw(width[j]);    这个是设置输出宽度的,但是默认是在右侧补充空格 所 ...

  4. UVa 400 (水题) Unix ls

    题意: 有n个文件名,排序后按列优先左对齐输出.设最长的文件名的长度为M,则最后一列长度为M,其他列长度为M+2. 分析: 这道题很简单,但要把代码写的精炼,还是要好好考虑一下的.lrj的代码中有两个 ...

  5. UVa 11040 (水题) Add bricks in the wall

    题意: 45块石头如图排列,每块石头上的数等于下面支撑它的两数之和,求其余未表示的数. 分析: 首先来计算最下面一行的数,A71 = A81 + A82 = A91 + 2A92 + A93,变形得到 ...

  6. Square Numbers UVA - 11461(水题)

    #include <iostream> #include <cstdio> #include <sstream> #include <cstring> ...

  7. UVa 489 HangmanJudge --- 水题

    UVa 489 题目大意:计算机给定一个单词让你猜,你猜一个字母,若单词中存在你猜测的字母,则会显示出来,否则算出错, 你最多只能出错7次(第6次错还能继续猜,第7次错就算你失败),另注意猜一个已经猜 ...

  8. UVa 1339 Ancient Cipher --- 水题

    UVa 1339 题目大意:给定两个长度相同且不超过100个字符的字符串,判断能否把其中一个字符串重排后,然后对26个字母一一做一个映射,使得两个字符串相同 解题思路:字母可以重排,那么次序便不重要, ...

  9. UVa 1225 Digit Counting --- 水题

    UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现 ...

随机推荐

  1. spring mvc Controller与jquery Form表单提交代码demo

    1.JSP表单 <% String basePath = request.getScheme() + "://" + request.getServerName() +&qu ...

  2. LA 3713

    The Bandulu Space Agency (BSA) has plans for the following three space missions: Mission A: Landing ...

  3. Android 检查设备是否存在 导航栏 NavigationBar

    尊重原创.尊重作者,转载请标明出处: http://blog.csdn.net/lnb333666/article/details/41821149 目前也没有可靠的方法来检查设备上是否有导航栏.可以 ...

  4. ElasticSearch使用IK中文分词---安装步骤记录

    提示1:必须保证之前的ES中不存在index, 否则ES集群无法启动, 会提示red! 提示2:下载的IK如果太新,会报错 TokenStream被重载Caused by: java.lang.Ver ...

  5. House Robber II

    https://leetcode.com/problems/house-robber-ii/ Note: This is an extension of House Robber. After rob ...

  6. 快速创建maven 工程:simple java工程,webapp

    http://www.cnblogs.com/buhaiqing/archive/2012/11/04/2754187.html 会从maven的Repository里查找所有支持的arche typ ...

  7. java、el表达式中保留小数的方法

    Java中: import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; p ...

  8. SPRING IN ACTION 第4版笔记-第十章Hitting the database with spring and jdbc-001-Spring对原始JDBC的封装

    1.spring扩展的jdbc异常 2.Template的运行机制 Spring separates the fixed and variable parts of the data-access p ...

  9. HTML5文档结构语义:页眉的header和hgroup标签使用

    HTML5提供了新的结构元素——例如header.hgroup.article.section.footer.nav等来定义网页,将使网页结构更加简洁严谨,语义更加结构化,而不用迂回通过class或i ...

  10. scala函数式编程

    1.作为值的函数 在Scala中,函数和数字一样,可以在变量中存放函数.可以把函数赋值给一个变量,格式为:val foee=fun _(函数名+空格+_)形式 2.匿名函数 在scala中,不需要给每 ...