Good Bye 2018 B

Problem Statement

Bob is a pirate looking for the greatest treasure the world has ever seen. The treasure is located at the point T, which coordinates to be found out.

Bob travelled around the world and collected clues of the treasure location at n obelisks. These clues were in an ancient language, and he has only decrypted them at home. Since he does not know which clue belongs to which obelisk, finding the treasure might pose a challenge. Can you help him?

As everyone knows, the world is a two-dimensional plane. The i-th obelisk is at integer coordinates (xi,yi). The j-th clue consists of 2 integers (aj,bj) and belongs to the obelisk pj, where p is some (unknown) permutation on n elements. It means that the treasure is located at T=(xpj+aj,ypj+bj). This point T is the same for all clues.

In other words, each clue belongs to exactly one of the obelisks, and each obelisk has exactly one clue that belongs to it. A clue represents the vector from the obelisk to the treasure. The clues must be distributed among the obelisks in such a way that they all point to the same position of the treasure.

Your task is to find the coordinates of the treasure. If there are multiple solutions, you may print any of them.

Note that you don’t need to find the permutation. Permutations are used only in order to explain the problem.

Input

The first line contains an integer n (1≤n≤1000) — the number of obelisks, that is also equal to the number of clues.

Each of the next n lines contains two integers xi, yi (−106≤xi,yi≤106) — the coordinates of the i-th obelisk. All coordinates are distinct, that is xi≠xj or yi≠yj will be satisfied for every (i,j) such that i≠j.

Each of the next n lines contains two integers ai, bi (−2⋅106≤ai,bi≤2⋅106) — the direction of the i-th clue. All coordinates are distinct, that is ai≠aj or bi≠bj will be satisfied for every (i,j) such that i≠j.

It is guaranteed that there exists a permutation p, such that for all i,j it holds (xpi+ai,ypi+bi)=(xpj+aj,ypj+bj).

Output

Output a single line containing two integers Tx,Ty — the coordinates of the treasure.

If there are multiple answers, you may print any of them.

Examples

input1

2
2 5
-6 4
7 -2
-1 -3

output1

1 2

input2

4
2 2
8 2
-7 0
-2 6
1 -14
16 -12
11 -18
7 -14

output2

9 -12

Note

As n=2, we can consider all permutations on two elements.

If p=[1,2], then the obelisk (2,5) holds the clue (7,−2), which means that the treasure is hidden at (9,3). The second obelisk (−6,4) would give the clue (−1,−3) and the treasure at (−7,1). However, both obelisks must give the same location, hence this is clearly not the correct permutation.

If the hidden permutation is [2,1], then the first clue belongs to the second obelisk and the second clue belongs to the first obelisk. Hence (−6,4)+(7,−2)=(2,5)+(−1,−3)=(1,2), so T=(1,2) is the location of the treasure.

In the second sample, the hidden permutation is [2,3,4,1].

问题陈述

鲍勃是一位正在寻找世界上最伟大财富的海盗。宝藏位于T点,协调发现。

鲍勃走遍世界各地,收集了方尖碑上宝藏位置的线索。这些线索是古老的语言,他只在家里解密。由于他不知道哪个线索属于哪个方尖碑,找到宝藏可能会带来挑战。你能帮助他吗?

众所周知,世界是一个二维平面。第i个方尖碑位于整数坐标(xi,yi)。第j个线索由2个整数(aj,bj)组成,属于方尖碑pj,其中p是n个元素上的一些(未知)排列。这意味着宝藏位于T =(xpj + aj,ypj + bj)。对于所有线索,这一点T是相同的。

换句话说,每条线索都属于一个方尖碑,每个方尖碑都只有一条属于它的线索。线索代表从方尖碑到宝藏的矢量。必须在方尖碑之间分配线索,使它们都指向宝藏的相同位置。

你的任务是找到宝藏的坐标。如果有多种解决方案,您可以打印其中任何一种。

请注意,您不需要查找排列。排列仅用于解释问题。

输入

第一行包含一个整数n(1≤n≤1000) – 方尖碑的数量,也等于线索的数量。

接下来的n行中的每一行包含两个整数xi,yi(-106≤xi,yi≤106) – 第i个方尖碑的坐标。所有坐标都是不同的,即对于每个(i,j)将满足xi≠xj或yi≠yj,使得i≠j。

接下来的n行中的每一行包含两个整数ai,bi(-2⋅106≤ai,bi≤2⋅106) – 第i个线索的方向。所有坐标都是不同的,即ai≠aj或bi≠bj将满足每个(i,j),使得i≠j。

保证存在置换p,使得对于所有i,j它保持(xpi + ai,ypi + bi)=(xpj + aj,ypj + bj)。

产量

输出一行包含两个整数Tx,Ty – 宝藏的坐标。

如果有多个答案,您可以打印其中任何一个。

我的理解,每个点是方尖塔的位置,经过位移得到宝藏的位置,因为位置相同所以宝藏的所有位置加起来除以n就是宝藏的位置

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct place{
    long long x;
    long long y;
};
int main(){
    int n;
    scanf("%d",&n);
    n*=2;
    long long sumx=0,sumy=0;
    struct place *p=(struct place *)malloc(sizeof(struct place) * n);
    for(int i=0; i<n; i++){
        scanf("%lld %lld",&p[i].x,&p[i].y);
        sumx+=p[i].x;
        sumy+=p[i].y;

    }
    n/=2;
    printf("%lld %lld",sumx/n,sumy/n);
    free(p);

return 0;
}//其实坐标可以不用long long, sum还是用long long比较保险一点
发布了65 篇原创文章 · 获赞 3 · 访问量 1万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 书香水墨 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览