UVA 10585 - Center of Symmetry

7 篇文章 0 订阅

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.


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

1
8
1 10
3 6
6 8
6 2
3 -4
1 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值