codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1091B.md (3554B)


      1 Source: https://codeforces.com/problemset/problem/1091/B
      2 
      3 B. New Year and the Treasure Geolocation
      4 
      5 time limit per test
      6 
      7 1.5 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 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?
     24 
     25 As everyone knows, the world is a two-dimensional plane. The $i$-th obelisk is at integer coordinates $(x_i, y_i)$. The $j$-th clue consists of $2$ integers $(a_j, b_j)$ and belongs to the obelisk $p_j$, where $p$ is some (unknown) permutation on $n$ elements. It means that the treasure is located at $T=(x_{p_j} + a_j, y_{p_j} + b_j)$. This point $T$ is the same for all clues.
     26 
     27 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.
     28 
     29 Your task is to find the coordinates of the treasure. If there are multiple solutions, you may print any of them.
     30 
     31 Note that you don't need to find the permutation. Permutations are used only in order to explain the problem.
     32 
     33 Input
     34 
     35 The first line contains an integer $n$ ($1 \leq n \leq 1000$) — the number of obelisks, that is also equal to the number of clues.
     36 
     37 Each of the next $n$ lines contains two integers $x_i$, $y_i$ ($-10^6 \leq x_i, y_i \leq 10^6$) — the coordinates of the $i$-th obelisk. All coordinates are distinct, that is $x_i \neq x_j$ or $y_i \neq y_j$ will be satisfied for every $(i, j)$ such that $i \neq j$.
     38 
     39 Each of the next $n$ lines contains two integers $a_i$, $b_i$ ($-2 \cdot 10^6 \leq a_i, b_i \leq 2 \cdot 10^6$) — the direction of the $i$-th clue. All coordinates are distinct, that is $a_i \neq a_j$ or $b_i \neq b_j$ will be satisfied for every $(i, j)$ such that $i \neq j$.
     40 
     41 It is guaranteed that there exists a permutation $p$, such that for all $i,j$ it holds $\left(x_{p_i} + a_i, y_{p_i} + b_i\right) = \left(x_{p_j} + a_j, y_{p_j} + b_j\right)$.
     42 
     43 Output
     44 
     45 Output a single line containing two integers $T_x, T_y$ — the coordinates of the treasure.
     46 
     47 If there are multiple answers, you may print any of them.
     48 
     49 Examples
     50 
     51 Input
     52 
     53 ```
     54 2
     55 2 5
     56 -6 4
     57 7 -2
     58 -1 -3
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 1 2
     65 ```
     66 
     67 Input
     68 
     69 ```
     70 4
     71 2 2
     72 8 2
     73 -7 0
     74 -2 6
     75 1 -14
     76 16 -12
     77 11 -18
     78 7 -14
     79 ```
     80 
     81 Output
     82 
     83 ```
     84 9 -12
     85 ```
     86 
     87 Note
     88 
     89 As $n = 2$, we can consider all permutations on two elements.
     90 
     91 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.
     92 
     93 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.
     94 
     95  ![](https://espresso.codeforces.com/7348d8de46d1d50daf4c26bd4f2915cc006e4219.png) 
     96 
     97 In the second sample, the hidden permutation is $[2, 3, 4, 1]$.