CF1091B.New Year and the Treasure Geolocation

普及-

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

Bob travelled around the world and collected clues of the treasure location at nn 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 ii-th obelisk is at integer coordinates (xi,yi)(x_i, y_i). The jj-th clue consists of 22 integers (aj,bj)(a_j, b_j) and belongs to the obelisk pjp_j, where pp is some (unknown) permutation on nn elements. It means that the treasure is located at T=(xpj+aj,ypj+bj)T=(x_{p_j} + a_j, y_{p_j} + b_j). This point TT 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.

鲍勃是一名海盗,正在寻找世界上有史以来最伟大的宝藏。宝藏位于点 TT,其坐标需要被确定。

鲍勃环游世界,在 nn 座方尖碑处收集到了有关宝藏位置的线索。这些线索使用一种古老语言书写,他直到回家后才将其破译。由于他不知道每条线索对应哪一座方尖碑,因此要找到宝藏可能颇具挑战性。你能帮他吗?

众所周知,世界是一个二维平面。第 ii 座方尖碑位于整数坐标 (xi,yi)(x_i, y_i) 处。第 jj 条线索由两个整数 (aj,bj)(a_j, b_j) 组成,并属于方尖碑 pjp_j,其中 pp 是 nn 个元素上的某个(未知)排列。这意味着宝藏位于点 T=(xpj+aj, ypj+bj)T = (x_{p_j} + a_j,\ y_{p_j} + b_j)。该点 TT 对所有线索均相同。

换言之,每条线索恰好属于一座方尖碑,且每座方尖碑恰好拥有一条属于它的线索。每条线索表示从其所归属的方尖碑指向宝藏的向量。线索必须以某种方式分配给各座方尖碑,使得它们全部指向同一宝藏位置。

你的任务是求出宝藏的坐标。若存在多个解,输出任意一个即可。

注意:你无需找出该排列 pp;该排列仅用于解释题意。

输入格式

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

Each of the next nn lines contains two integers xix_i, yiy_i (−106≤xi,yi≤106-10^6 \leq x_i, y_i \leq 10^6) — the coordinates of the ii-th obelisk. All coordinates are distinct, that is xi≠xjx_i \neq x_j or yi≠yjy_i \neq y_j will be satisfied for every (i,j)(i, j) such that i≠ji \neq j.

Each of the next nn lines contains two integers aia_i, bib_i (−2⋅106≤ai,bi≤2⋅106-2 \cdot 10^6 \leq a_i, b_i \leq 2 \cdot 10^6) — the direction of the ii-th clue. All coordinates are distinct, that is ai≠aja_i \neq a_j or bi≠bjb_i \neq b_j will be satisfied for every (i,j)(i, j) such that i≠ji \neq j.

It is guaranteed that there exists a permutation pp, such that for all i,ji,j it holds (xpi+ai,ypi+bi)=(xpj+aj,ypj+bj)\left(x_{p_i} + a_i, y_{p_i} + b_i\right) = \left(x_{p_j} + a_j, y_{p_j} + b_j\right).

第一行包含一个整数 nn(1≤n≤10001 \leq n \leq 1000)—— 表示方尖碑的数量,也等于线索的数量。

接下来的 nn 行中,每行包含两个整数 xix_i、yiy_i(−106≤xi,yi≤106-10^6 \leq x_i, y_i \leq 10^6)—— 表示第 ii 个方尖碑的坐标。所有坐标互不相同,即对任意满足 i≠ji \neq j 的 (i,j)(i, j),均有 xi≠xjx_i \neq x_j 或 yi≠yjy_i \neq y_j。

再接下来的 nn 行中,每行包含两个整数 aia_i、bib_i(−2⋅106≤ai,bi≤2⋅106-2 \cdot 10^6 \leq a_i, b_i \leq 2 \cdot 10^6)—— 表示第 ii 个线索的方向向量。所有方向向量互不相同,即对任意满足 i≠ji \neq j 的 (i,j)(i, j),均有 ai≠aja_i \neq a_j 或 bi≠bjb_i \neq b_j。

题目保证存在一个排列 pp,使得对所有 i,ji,j 均有 (xpi+ai,ypi+bi)=(xpj+aj,ypj+bj)\left(x_{p_i} + a_i, y_{p_i} + b_i\right) = \left(x_{p_j} + a_j, y_{p_j} + b_j\right)。

输出格式

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

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

输出一行,包含两个整数 Tx,TyT_x, T_y —— 表示宝藏的坐标。

如果存在多个答案,你可以输出其中任意一个。

输入输出样例

  • 输入#1

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

    输出#1

    1 2
  • 输入#2

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

    输出#2

    9 -12

说明/提示

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

If p=[1,2]p = [1, 2], then the obelisk (2,5)(2, 5) holds the clue (7,−2)(7, -2), which means that the treasure is hidden at (9,3)(9, 3). The second obelisk (−6,4)(-6, 4) would give the clue (−1,−3)(-1,-3) and the treasure at (−7,1)(-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][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)(-6, 4) + (7, -2) = (2,5) + (-1,-3) = (1, 2), so T=(1,2)T = (1,2) is the location of the treasure.

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

当 n=2n = 2 时,我们可以枚举所有作用于两个元素的排列。

若 p=[1,2]p = [1, 2],则方尖碑 (2,5)(2, 5) 给出线索 (7,−2)(7, -2),意味着宝藏藏在 (9,3)(9, 3) 处;而第二座方尖碑 (−6,4)(-6, 4) 给出的线索为 (−1,−3)(-1, -3),对应宝藏位置 (−7,1)(-7, 1)。但两座方尖碑必须给出同一处宝藏位置,因此该排列显然不正确。

若隐藏的排列为 [2,1][2, 1],则第一条线索属于第二座方尖碑,第二条线索属于第一座方尖碑。于是有:

(−6,4)+(7,−2)=(2,5)+(−1,−3)=(1,2),(-6, 4) + (7, -2) = (2, 5) + (-1, -3) = (1, 2),

因此宝藏位置为 T=(1,2)T = (1, 2)。

在第二个样例中,隐藏的排列为 [2,3,4,1][2, 3, 4, 1]。

输入解题思路,AI测评打分。不知道怎么写?

首页