---恢复内容开始---

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

分析:我的思路是输入的同时,记下某一行的x的最大值和最小值,通过这一行的对称轴,再默认已它为所有行的对称轴去判断是否适用其他行,没有冲突即找到对称轴。

我的代码

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;struct point
{double x, y;point(int x1 = 0, int y1 = 0) :x(x1), y(y1){}void mirror(){x = -x;}bool operator <(const point &b)const{if (x == b.x){return  (y< b.y);}else{return x < b.x;}}}p[1010];map<point, bool> m;bool findmirror(point & p1, double x)
{point tempp;tempp.x = 2 * x - p1.x;tempp.y = p1.y;//auto result =m.find(tempp);if (m[tempp]){return true;}return false;
}int Max = -15000;
int Min = 15000;int main()
{int t;        cin >> t;while (t--){m.clear();bool flag = true;Max = -15000;Min = 15000;int n;cin >> n;//输入for (int i = 0; i < n; i++){cin >> p[i].x >> p[i].y;m[p[i]] = true;if (p[i].y == p[0].y){if (Max < p[i].x)                Max = p[i].x;if (Min>p[i].x)                Min = p[i].x;}}//判断double mir = (double)(Max + Min) / 2;for (int i = 0; i < n; i++){if (  !findmirror(p[i], mir)      ){flag = false;break;}}if (flag == true)puts("YES");elseputs("NO");}return 0;
}

View Code

转载于:https://www.cnblogs.com/shawn-ji/p/4656817.html

Symmetry 解题心得相关推荐

  1. wechall.net/stegano 解题心得

    /* 转载请注明出处:http://www.cnblogs.com/Martinium/p/wechall_stegano.html */ 最近迷上了 www.wechall.net 网站,里面都是些 ...

  2. 动态规划:openjudge 2.6-3532 最大上升子序列和 解题心得

    传送门 题目描述 一个数的序列bi,当b1 < b2 < - < bS的时候,我们称这个序列是上升的.对于给定的一个序列(a1, a2, -,aN),我们可以得到一些上升的子序列(a ...

  3. 高通平台Linux kernel死机解题心得-trace32的使用

    1.前言 1.1 目的 能够结合知识背景,借助相关调试工具,使用一般分析手段分析.定位解决项目过程中遇到的死机类系统稳定性问题,提升工作效率 持续积累,拓宽知识深度和广度 1.2 死机? 指系统发生致 ...

  4. LeetCode -- 力扣算法题解题心得 -- (个人笔记记录)持续更新~~

    一.前言 正式开启数据结构+算法研究的历程,准备好一年后的面试.下面的解法不一定是最优解,只求能力提升,会定期更新~~ 二.目录 1 2 19 20 21 24 35 42 83 86 94 96 1 ...

  5. HDU 4911 Inversion - 疯狂的癫子 解题心得

    原题: Description bobo has a sequence a 1,a 2,-,a n. He is allowed to swap two adjacent numbers for no ...

  6. 2021-01-25广州大学ACM寒假训练赛解题心得

    https://vjudge.net/contest/419545 目录 A - Airplane AtCoder - abc129_a B - Balance AtCoder - abc129_b ...

  7. BalalaPower个人解题心得

    点击打开HDU直通车   Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K ( ...

  8. WOJ 1006-Language of Animals解题心得

    作为Java选手感觉受到了歧视...一样的代码逻辑java就疯狂超时,c++瞬间秒杀

  9. 洛谷P1765解题心得

    题是水题,但给人灵活使用数组的启发 如果刚学循环,那我肯定就一个劲的if        if...了 但可以用数组把需要按下相同次数的字母(空格)放在一类,搜索的话就方便多了 #include < ...

最新文章

  1. 边工作边刷题:70天一遍leetcode: day 27
  2. Linux系统的安装(自动引导安装、网络安装、分区选择)
  3. android 缓存文件目录在哪个文件夹里,Android 文件目录存储介绍 缓存目录 | 私有目录 | 系统根目录 | 用户可见目录...
  4. 北航计算机考研 跨考,过来人分享:给外校跨考北航同学的建议
  5. win7配置远程连接oracle数据库吗,win7环境下配置oracle数据库的方法有哪些?
  6. 定位Flutter内存问题很难么?
  7. 【python】获取51cto博客的文章列表
  8. Github fork其他项目的分支与主干保持同步
  9. CentOS 5/6下安装Axel插件加速yum下载
  10. websocket替代方案_码农手记 | 前后端实时交互方案概述
  11. 创业当然比守业难太多
  12. vue 检测ie版本_vue 兼容低版本ie浏览器
  13. 学习QT之位置相关函数
  14. H264格式详细说明
  15. Robocup 仿真2D 学习笔记(一) ubuntu16.04 搭建 robocup 仿真2D环境
  16. 宇视科技的摄像头添加至别的品牌录像机黑屏
  17. 河北钢铁的数字化雄心
  18. px,in,mm,pt,dp,dip,sp 之间的换算公式以及区别 屏幕密度
  19. Linux内核(10) - 内核中的链表
  20. poco新增对cocos c++项目的支持~

热门文章

  1. Java 线程实现两个方法同时运行
  2. 音箱参数记录和说明讲解
  3. 【Simulink】基于FCS-MPC的单相并网逆变器控制(Matlab Function)
  4. 数据结构 栈-链栈及基本操作
  5. Clumsy-Windows下网络环境模拟工具
  6. 计算机的收获初一作文,我的收获作文700字
  7. 机器学习算法之朴素贝叶斯模型
  8. Mac 连接iPhone或者iPad出现闪断电
  9. DolphinScheduler
  10. 使用宝塔面板搭建 WordPress 站点