codeforces-scrape

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

1237C1.md (2425B)


      1 Source: https://codeforces.com/problemset/problem/1237/C1
      2 
      3 C1. Balanced Removals (Easier)
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 512 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 This is an easier version of the problem. In this version, $n \le 2000$.
     22 
     23 There are $n$ distinct points in three-dimensional space numbered from $1$ to $n$. The $i$-th point has coordinates $(x_i, y_i, z_i)$. The number of points $n$ is even.
     24 
     25 You'd like to remove all $n$ points using a sequence of $\frac{n}{2}$ snaps. In one snap, you can remove any two points $a$ and $b$ that have not been removed yet and form a perfectly balanced pair. A pair of points $a$ and $b$ is perfectly balanced if no other point $c$ (that has not been removed yet) lies within the axis-aligned minimum bounding box of points $a$ and $b$.
     26 
     27 Formally, point $c$ lies within the axis-aligned minimum bounding box of points $a$ and $b$ if and only if $\min(x_a, x_b) \le x_c \le \max(x_a, x_b)$, $\min(y_a, y_b) \le y_c \le \max(y_a, y_b)$, and $\min(z_a, z_b) \le z_c \le \max(z_a, z_b)$. Note that the bounding box might be degenerate.
     28 
     29 Find a way to remove all points in $\frac{n}{2}$ snaps.
     30 
     31 Input
     32 
     33 The first line contains a single integer $n$ ($2 \le n \le 2000$; $n$ is even), denoting the number of points.
     34 
     35 Each of the next $n$ lines contains three integers $x_i$, $y_i$, $z_i$ ($-10^8 \le x_i, y_i, z_i \le 10^8$), denoting the coordinates of the $i$-th point.
     36 
     37 No two points coincide.
     38 
     39 Output
     40 
     41 Output $\frac{n}{2}$ pairs of integers $a_i, b_i$ ($1 \le a_i, b_i \le n$), denoting the indices of points removed on snap $i$. Every integer between $1$ and $n$, inclusive, must appear in your output exactly once.
     42 
     43 We can show that it is always possible to remove all points. If there are many solutions, output any of them.
     44 
     45 Examples
     46 
     47 Input
     48 
     49 ```
     50 6
     51 3 1 0
     52 0 3 0
     53 2 2 0
     54 1 0 0
     55 1 3 0
     56 0 1 0
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 3 6
     63 5 1
     64 2 4
     65 ```
     66 
     67 Input
     68 
     69 ```
     70 8
     71 0 1 1
     72 1 0 1
     73 1 1 0
     74 1 1 1
     75 2 2 2
     76 3 2 2
     77 2 3 2
     78 2 2 3
     79 ```
     80 
     81 Output
     82 
     83 ```
     84 4 5
     85 1 6
     86 2 7
     87 3 8
     88 ```
     89 
     90 Note
     91 
     92 In the first example, here is what points and their corresponding bounding boxes look like (drawn in two dimensions for simplicity, as all points lie on $z = 0$ plane). Note that order of removing matters: for example, points $5$ and $1$ don't form a perfectly balanced pair initially, but they do after point $3$ is removed.
     93 
     94  ![](https://espresso.codeforces.com/167454c917d62a801abf3bf4c75746f11b6da23e.png)