UVA 10585 - Center of Symmetry
来源:互联网 发布:java程序员面试一年 编辑:程序博客网 时间:2024/06/05 00:35
Description
Given is a set of n points with integer coordinates. Your task is to decide whether the set has a center of symmetry.
A set of points S has the center of symmetry if there exists a point s (not necessarily in S) such that for every point p in S there exists a point q in S such that p-s = s-q.
A set of points S has the center of symmetry if there exists a point s (not necessarily in S) such that for every point p in S there exists a point q in S such that p-s = s-q.
Input
The first line of input contains a number c giving the number of cases that follow. The first line of data for a single case contains number 1 <= n <= 10000. The subsequent n lines contain two integer numbers each which are the x and y coordinates of a point. Every point is unique and we have that -10000000 <= x, y <= 10000000.
Output
For each set of input data print yes if the set of points has a center of symmetry and no otherwise.
Sample Input
181 103 66 86 23 -41 0-2 -2-2 4
Sample Output
yes
题意:给出一个 T 表示有 T 组输入数据,每个测试数据有一个 N,表示有 N 个点,每个点给出x和y,问这个图形是否关于一点对称。
通过排序,然后计算出每对点的中点,只要所有的点的中点都是一样就可以是yes。
#include <cstdio>#include <algorithm>using namespace std;struct node{ int x, y;};node point[10005];int cmp(node a, node b){ if (a.x == b.x) return a.y < b.y; return a.x < b.x;}int main(){ int T; int n; scanf("%d", &T); while (T--) { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d%d", &point[i].x, &point[i].y); sort(point, point + n, cmp); int flag = 1; int sym_x = point[0].x + point[n-1].x; int sym_y = point[0].y + point[n-1].y; for (int i = 1; i < n/2; ++i) { int j = n - i -1; if (point[i].x + point[j].x != sym_x || point[i].y + point[j].y != sym_y) { flag = 0; break; } } if (flag == 1) printf("yes\n"); else printf("no\n"); } return 0;}
0 0
- Uva 10585 - Center of symmetry
- UVA 10585 - Center of symmetry
- UVa 10585 - Center of symmetry
- UVA 10585 Center of symmetry
- UVA 10585 - Center of Symmetry
- uva 10585 - Center of symmetry(水)
- UVA10585-Center of symmetry
- POJ 2526 Center of symmetry 笔记
- poj 2526 Center of symmetry 哈希查找
- POJ 1859 The Perfect Symmetry && POJ2526 Center of symmetry(思维题)
- Symmetry UVA
- Symmetry UVA
- UVA 10002 Center of Masses
- UVa 10002 - Center of Masses
- UVA 10002 Center of Masses【求凸包重心】
- UVA 10002 Center of Masses(凸包)
- UVa 1595 Symmetry
- UVA - 1595 Symmetry
- 【OpenCV入门教程之十五】水漫金山:OpenCV漫水填充算法(Floodfill)
- 将文件以流的方式存到数据库某个字段中,并且可以从数据库字段中取出来
- spark本地模式
- 《浪潮之巅》第二章 蓝色巨人 IBM公司
- 解决IIS对COM组件的访问异常
- UVA 10585 - Center of Symmetry
- java 5新特性--静态导入
- 产品为何总是做不好 (四): 只願意很聰明的去做 ⋯ 亮點實踐
- 反射遍历解决方案中所有窗体
- 新博客搭建完成啦
- Getting Started with Redux: An Intro
- 【JZOJ4744】【NOIP2016提高A组模拟9.2】同余
- 每天一条linux--more命令
- 09/02号 课外扩展知识面,学习别人的博客笔记或者网站内容