1595 - Symmetry

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

题解:刘汝佳白书135页练习题5.6;本题能够考虑暴力求解,也能够用set的查找来进行;

code:

#include <iostream>

#include <set>

#include <string>

using namespace std;

typedef pair<int,int> point;//定义类型;(不能够用预处理)

set<point> se;

int main()

{

    int cas;

    int n;

    int x,y;

    cin>>cas;

    while(cas--)

    {

        se.clear();

        cin>>n;

        int sum=0;

        for(int i=0; i<n; i++)

        {

            cin>>x>>y;

            sum+=x;//将全部横坐标加和;

            se.insert(point(x*n,y));//(备注1)

        }

        /*
        set<point> ::iterator it;

        for(it=se.begin(); it!=se.end(); ++it)

        {

            point p=*it;

            cout<<p.first<<"  "<<p.second<<endl;

        }
        */

        set<point> ::iterator it;

        bool flag = true;

        for(it=se.begin(); it!=se.end(); ++it)

        {

            point p=*it;

            if(se.find(point(2*sum-p.first,p.second))==se.end())

            {

                flag=false;

                break;

            }

        }

        flag?

cout<<"YES"<<endl: cout<<"NO"<<endl;

    }

    return 0;

}

备注1:

x*n的意思,就是存储的时候将横坐标扩大n倍,由于对称轴肯定是竖线,所以如果对称的话全部的横坐标加和再与n想除得出的应该就是答案的x坐标;之所以不是将sum/n。是由于考虑到精度的问题。除的话会出现double类型;换而言之,这个存储方式就是将全部横坐标扩大了n倍;

uvaoj-1595:symmetry的更多相关文章

  1. uva 1595 - Symmetry

    思路:首先,如果这些点对称,那么它们的对称轴是x = m(m是所有点横坐标的平均值):   把这些点放到一个集合里,然后扫描每个点,计算出它关于x = m的对称点,看这个点是否在集合里面.   如果有 ...

  2. uva 1595 Symmetry“结构体”

    给出平面上N(N<=1000)个点.问是否可以找到一条竖线,使得所有点左右对称,如图所示: 则左边的图形有对称轴,右边没有.   Sample Input  3 5 -2 5 0 0 6 5 4 ...

  3. 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 ...

  4. 【UVA】1595 Symmetry(模拟)

    题目 题目     分析 理清思路,上模拟.     代码 #include <bits/stdc++.h> using namespace std; const int maxn=100 ...

  5. UVa 1595 Symmetry (set && math)

    题意:给出n个在直角坐标系上的点,问你能不能找出一条竖轴(即垂直于x的轴)使得所有的点根据这条轴对称,能则输出YES,否则输出NO 分析:首先需要找到对称轴的值,将所有n个点的x轴的值加起来然后去除以 ...

  6. Uva 3226 Symmetry

    题目给出一些点的坐标(横坐标,纵坐标),没有重叠的点,求是否存在一条竖线(平行于y轴的线),使线两边的点左右对称. 我的思路:对于相同的纵坐标的点,即y值相同的点,可以将x的总和计算出,然后除以点的数 ...

  7. UVa 1595 (水题) Symmetry

    颓废的一个下午,一直在切水题,(ˉ▽ ̄-) 首先如果这些点是对称的话,那么它们的对称轴就是x = m,m是横坐标的平均值. 把这些点放到一个集合里,然后扫描每个点,计算出它关于x = m的对称点,看这 ...

  8. Symmetry UVA - 1595

      The figure shown on the left is left-right symmetric as it is possible to fold the sheet of paper ...

  9. ACM/ICPC 之 数论-素数筛选法 与 "打表"思路(POJ 1595)

    何为"打表"呢,说得简单点就是: 有时候与其重复运行同样的算法得出答案,还不如直接用算法把这组数据所有可能的答案都枚举出来存到一个足够大的容器中去-例如数组(打表),然后再输入数据 ...

随机推荐

  1. JAVA基础数据类型

    JAVA的数据类型粗略分两种 1.基本数据类型 整数类型: byte,short,int,long 浮点类型: float,double 字符类型: char 布尔类型: boolean 基本语法格式 ...

  2. php输出杨辉三角

    php输出杨辉三角 一.截图 二.代码 <!DOCTYPE html> <html lang="en"> <head> <meta cha ...

  3. rtsp和sdp协议简介

    RTSP是由Real network 和Netscape共同提出的如何有效地在IP网络上传输流媒体数据的应用层协议. 实时流协议(RTSP)建立并控制一个或几个时间同步的连续流媒体,如音频和视频.尽管 ...

  4. 突破极限 解决大硬盘上安装Unix新思路

    一.问题提出 硬盘越做越大,然我喜欢让我忧.10年前就遇到过在586电脑BIOS不认识超过8.4G容量硬盘的问题,以及Windows Nt操作系统不认大硬盘(容量超过8.4G)的问题,对于Linux ...

  5. A股借壳上市?暂时没戏

    近期股市波动,让不少P2P概念股打回原型.同花顺数据显示,上周五P2P概念股整体下跌9.28%,其中除了5家上市公司停牌外,14家P2P概念股跌幅都超过了9%.此前大热的多伦股份自6月23日以来,股价 ...

  6. HUD——T 3836 Equivalent Sets

    http://acm.hdu.edu.cn/showproblem.php?pid=3836 Time Limit: 12000/4000 MS (Java/Others)    Memory Lim ...

  7. 洛谷 P1827 美国血统 American Heritage

    P1827 美国血统 American Heritage 题目描述 农夫约翰非常认真地对待他的奶牛们的血统.然而他不是一个真正优秀的记帐员.他把他的奶牛 们的家谱作成二叉树,并且把二叉树以更线性的“树 ...

  8. mac自己定义tree命令

    编辑文件: vim ~/.bash_profile 在文件末尾追加: alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____| ...

  9. shell date 命令说明

    shell date 命令说明 使用方法:date [选项]... [+格式] 或:date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] 以给定的格式 ...

  10. git 工具的使用总结(5)-查看历史记录

    1.查看历史记录git log 1)不加参数,显示的就是节点号,作者,日期,注释 commit b7b310d220628530d1feb9e8046ccb59039d59f2 Author: zha ...