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 ...
随机推荐
- JS之对象数组遍历?
一.js实现遍历对象 <script> ","destroy":"97%"}; var props = ""; for ...
- ssh登陆设置快捷方式
在自己的环境下配置 ~/.ssh/config Host k231 HostName 192.168.1.231 User kyee 原来ssh 登陆192.168.1.231 的命令是 ssh ky ...
- CentOS下php使用127.0.0.1不能连接mysql的解决方法
这篇文章主要介绍了CentOS下php使用127.0.0.1不能连接mysql的解决方法,本文原因是SELINUX导致的连接失败,需要的朋友可以参考下 php代码很简单: 复制代码代码如下: $ser ...
- 性能测试工具--SIEGE安装及使用简介
官方网站http://www.joedog.org/ 概述 Siege是一个多线程http负载测试和基准测试工具.它有3种操作模式: 1) Regression (when invoked by bo ...
- 转: pthread_detach()函数
创建一个线程默认的状态是joinable. 如果一个线程结束运行但没有被join,则它的状态类似于进程中的Zombie Process,即还有一部分资源没有被回收(退出状态码). 所以创建线程者应该调 ...
- MongoDB insert/update/one2many案例
以博文与评论为例,博文有标题内容,对应多个评论,评论有评论人.评论内容等. ()插入一条博文: db.blog.insert( {','title':'this is blog title1','co ...
- LeetCode _ Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point t ...
- 【HDOJ】3184 All Can Do
简单数学题. #include <cstdio> #include <cstring> #include <cstdlib> int main() { int t; ...
- Hadoop2.4.1 64-Bit QJM HA and YARN HA + Zookeeper-3.4.6 + Hbase-0.98.8-hadoop2-bin HA Install
Hadoop2.4.1 64-Bit QJM HA and YARN HA Install + Zookeeper-3.4.6 + Hbase-0.98.8-hadoop2-bin HA(Hadoop ...
- Junit 学习
一. 断言核心方法 示例代码: package com.test; import org.junit.Assert; import org.junit.Test; /** * @Title: test ...