Description

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 ( 1N1, 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 题意:
给出一张图,图上有一些点,你要做的就是找到一条线可以将这些点对称分开,如果能找到,输出yes,找不到输出no 思路:
最重要的一句“The figure on the right is not left-right symmetric as it is impossible to find such a vertical line”,vertical说明只需要垂直的竖线,那就好办多l
首先随便找到处于同一行的对称两点,通过它们求出中点,那么这条线就找到了。
然后枚举判断每一行的对称点到这条线的距离是否相等,如果不相等,马上break掉,输出no。
然后考虑数据结构,因为处在同一行的点你不知道会有多少,所以使用不定长数组vector会比较方便
再想到如果仅仅就以y为vector数组的下标,后面的枚举会不好进行,所以只需要开一个数组记录一下就好了,y的值是什么并不重要。
还有就是为了找到同一行对称两点,应该对那一行先排一下序,然后就好找了 代码:
#include"iostream"
#include"cstdio"
#include"cstring"
#include"vector"
#include"algorithm"
using namespace std;
const int maxn=10000+10; vector<int>pile[maxn];
int book[2*maxn+10];
int top,flag; void Init()
{
int n;
cin>>n;
memset(pile,0,sizeof(pile));
memset(book,0,sizeof(book));
top=1;
int x,y;
for(int i=0;i<n;i++)
{
cin>>x>>y;
y+=10000;
if(!book[y]) book[y]=top++;
pile[book[y]].push_back(x);
}
} void Work()
{
sort(pile[1].begin(),pile[1].end());
int mid=(pile[1][0]+pile[1][pile[1].size()-1])/2;
flag=0;
for(int k=1;k<top;k++)
{
sort(pile[k].begin(),pile[k].end());
for(int j=0;j<pile[k].size();j++)
{
if(((pile[k][j]+pile[k][pile[k].size()-j-1])/2)!=mid)
{
flag=1;
break;
}
}
if(flag) break;
}
} void Print()
{
cout<<(flag==1?"NO":"YES")<<endl;
} int main()
{
int T;
cin>>T;
while(T--)
{
Init();
Work();
Print();
}
return 0;
}

Symmetry的更多相关文章

  1. bzoj2592: [Usaco2012 Feb]Symmetry

    Description After taking a modern art class, Farmer John has become interested in finding geometric ...

  2. Symmetry(对称轴存在问题)

    Symmetry Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description   Th ...

  3. fzu 2035 Axial symmetry(枚举+几何)

    题目链接:fzu 2035 Axial symmetry 题目大意:给出n个点,表示n边形的n个顶点,判断该n边形是否为轴对称图形.(给出点按照图形的顺时针或逆时针给出. 解题思路:将相邻两个点的中点 ...

  4. [刷题]算法竞赛入门经典(第2版) 5-6/UVa1595 - Symmetry

    题意:平面上给若干点,问它们是不是关于某垂直于x轴的直线对称. 代码:(Wrong Answer, –ms) //UVa1595 - Symmetry #include<iostream> ...

  5. rosetta对称性文件(rosetta symmetry file)的产生及应用

    针对对称性PDB 3UKM,使用make_symmdef_file.pl脚本,可以执行产生对称单元及对称文件: $> $ROSETTA3/src/apps/public/symmetry/mak ...

  6. Codeforces Round #127 (Div. 1) A. Clear Symmetry 打表

    A. Clear Symmetry 题目连接: http://codeforces.com/contest/201/problem/A Description Consider some square ...

  7. Analysis Of The Causes Of Internal Symmetry Of Hydraulic Motor

    The main reasons why hydraulic motors have this symmetrical internal structure are as follows: The   ...

  8. uvaoj-1595:symmetry

    1595 - Symmetry The figure shown on the left is left-right symmetric as it is possible to fold the s ...

  9. 「JSOI2015」symmetry

    「JSOI2015」symmetry 传送门 我们先考虑构造出原正方形经过 \(4\) 种轴对称变换以及 \(2\) 种旋转变换之后的正方形都构造出来,然后对所得的 \(7\) 个正方形都跑一遍二维哈 ...

  10. symmetry methods for differential equations,exercise 1.4

    tex文档: \documentclass[a4paper, 12pt]{article} % Font size (can be 10pt, 11pt or 12pt) and paper size ...

随机推荐

  1. linux 文件 chgrp、chown、chmod

    linux 默认情况下有会提供6个terminal 来让用户登录,使用[Ctrl]+[Alt] +[F1]~[F6] 组合 linux 文件 任何一个文件都具有"user,Group及Oth ...

  2. Matlab实现图像分割 分类: 图像处理 2014-06-14 21:31 662人阅读 评论(1) 收藏

    下面使用极小值点阈值选取方法,编写MATLAB程序实现图像分割的功能. 极小值点阈值选取法即从原图像的直方图的包络线中选取出极小值点, 并以极小值点为阈值将图像转为二值图像 clear all; cl ...

  3. Android的handler消息机制

    Hnadler机制中有这么几部分构成,包括 handler.Message.Looper和MessageQueue.要想在一个线程中使用Handler的话必须要有Looper和MessageQueue ...

  4. dotnet cors 跨域问题

    研究了一整子的.net core框架,感觉挺好用的,可以用在实际项目中,前端avalon框架也在研究: 问题:跨域,相比原来的跨域解决方案,还是有不小的变化的,原来的.net api 只需要在WebA ...

  5. KMS

    slmgr -ipk 73KQT-CD9G6-K7TQG-66MRP-CQ22C

  6. cookie设置和读取以及获取超链接参数

    function setCookie(c_name, value, expiredays) { var exdate = new Date() exdate.setDate(exdate.getDat ...

  7. day25-2 OSI协议和socket抽象层

    目录 OSI协议 物理层 数据链路层 以太网协议 Mac地址 广播地址 网络层 获取对方Mac地址(ARP协议) 传输层 TCP协议 UDP协议 应用层 socket抽象层 OSI协议 互联网的本质就 ...

  8. freopen()重定向的打开和关闭

    freopen函数 功能 使用不同的文件或模式重新打开流,即重定向. 实现重定向,把预定义的标准流文件定向到由path指定的文件中.(直观感觉/实际操作都像是把文件定向到流,难道是说,对流来说就是重定 ...

  9. hibernate cascade属性

    cascade属性是存在于set标签中,用来做级联删除和保存. 它的值有以下几种: 1)默认值是none,不做级联动作: 2)save-update:级联保存 3)delete:级联删除 4)all: ...

  10. Zend Studio 离线汉化包下载方法

    进入eclipse官网 语言包位置 http://www.eclipse.org/babel/downloads.php