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. Centos6.5 安装lamp环境

    转载自:http://www.jb51.net/article/37987.htm (转载请注明出处,谢谢) 准备篇: 1.配置防火墙,开启80端口.3306端口vi /etc/sysconfig/i ...

  2. 【Henu ACM Round#14 F】 President and Roads

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 处理出起点到任意点的最短路以及最短路条数=>dis[0][i],cnt[0][i] 然后 把所有的边反向 处理出在反图上终点到 ...

  3. ios学习之旅------玩转结构体

    1.全局变量和局部变量 局部变量:     概念:定义函数内部变量     定义格式:变量类型 变量名称;     作用域:从定义那一行開始到所在代码块结束     生命周期:从代码运行到定义的哪一行 ...

  4. 用YourAPP开发网络状态提醒应用

    如今的通信真是方便,走到哪里都有网络.Wifi的利用已经到了很普及的程度.即使走到没有wifi信号的地方,利用手机信号也能上网.(若是连手机信号都没有,那就没办法了) 智能手机的使用也大慷慨面了各个年 ...

  5. 实用的 Python 包 —— 使用 win32 的剪贴板

    1. usage >> import win32clipboard >> win32clipboard.OpenClipboard() >> win32clipbo ...

  6. 懒加载js实现和优化

    1.懒加载的作用和原理 在我们展示多图片的场景下,类似淘宝或者百度图片,由于图片的数目过多,全部从服务器请求会给用户糟糕的用户体验,为了提升用户体验,我们这里使用懒加载,随着下拉逐步加载. 每个图片的 ...

  7. express中的中间件理解

    什么是中间件 中间件是一个可访问请求对象(req)和响应对象(res)的函数,在 Express 应用的请求-响应循环里,下一个内联的中间件通常用变量 next 表示.中间件的功能包括: 执行任何代码 ...

  8. zhizhang错误(每天更新更新)

    做题反思(Think twice ,Code once) 1.2013NOIP转圈游戏,交代码前一定要静态查错,看看代码写得和自己意思一不一样,竟然把变量n写成了常数10,低级错误 2.2013NOI ...

  9. Laravel输出sql语句

    $queries = DB::getQueryLog();

  10. 今日SGU 5.5

    SGU 114 题意:求一个点到其他点的距离总和最小,距离的定义是x轴距离乘以那个点的人数p 收获:带权中位数,按坐标排序,然后扫一遍,最后权值超过或等于总权值的一半时的那个点就是答案,证明暂无 #i ...