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. 基于zookeeper实现分布式配置中心(二)

    上一篇(基于zookeeper实现分布式配置中心(一))讲述了zookeeper相关概念和工作原理.接下来根据zookeeper的特性,简单实现一个分布式配置中心. 配置中心的优势 1.各环境配置集中 ...

  2. .Net视图机制

    .Net会有默认的约定. HomeController下面的Index,会默认渲染Home/Index.cshtml. 当然可以设置成别的,比如设置成About. using System; usin ...

  3. 轻松使用 Redis slowlog

    之前中秋项目搞活动,用户比较活跃 SE.Redis 频繁报 Timeout 异常,狂翻了一波 issues 发现提这个问题还蛮多的,作者非常频繁的提到使用 slowlog 这个命令进行排查,那么问题就 ...

  4. Shiro结合Redis解决集群中session同步问题

    pom.xml文件中引入redis的依赖 在application.xml配置redis: <bean id="jedisConnectionFactory" class=& ...

  5. RTSP传输协议之Methods总结

    RTSP/1.0 200 OK Server: DSS/5.5.5 (Build/489.16; Platform/Linux; Release/Darwin; state/beta; ) Cseq: ...

  6. 高阶函数sort

    排序中我们经常会用sort这个高阶函数,我们今天就来讲讲这个sort的比较机制,对于数字来说我们只需要比较他们的大小就可以了 但是 var arr =[15,81,9,4,3]; alert(arr. ...

  7. CSU 1046 追杀

    Description 在一个8行9列的国际象棋棋盘上,有一名骑士在追杀对方的国王.该骑士每秒跨越一个2*3的区域,如下图所示. 而对方的国王慌忙落逃,他先沿着右下斜线方向一直跑,遇到边界以后会沿着光 ...

  8. CString与 char *之间的转换

    http://www.cnblogs.com/watsonlong/archive/2011/04/15/2017086.html

  9. 微信小程序从零开始开发步骤(三)底部导航栏

    上一章节,我们分享了如何创建一个新的页面和设置页面的标题,这一章我们来聊聊底部导航栏是如何实现的.即点击底部的导航,会实现不同对应页面之间的切换. 我们先来看个我们要实现的底部导航栏的效果图:(三个导 ...

  10. 【Uva 12093】Protecting Zonk

    [Link]: [Description] n个节点的树; 每个节点都可以选择3种 1.覆盖和它相连的边; c1花费; 2.覆盖和它相连的边以及和它相连的点相连的边; c2花费; 3.不进行操作 覆盖 ...