codeforces-scrape

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

1173B.md (2414B)


      1 Source: https://codeforces.com/problemset/problem/1173/B
      2 
      3 B. Nauuo and Chess
      4 
      5 time limit per test
      6 
      7 1 second
      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 Nauuo is a girl who loves playing chess.
     22 
     23 One day she invented a game by herself which needs $n$ chess pieces to play on a $m\times m$ chessboard. The rows and columns are numbered from $1$ to $m$. We denote a cell on the intersection of the $r$-th row and $c$-th column as $(r,c)$.
     24 
     25 The game's goal is to place $n$ chess pieces numbered from $1$ to $n$ on the chessboard, the $i$-th piece lies on $(r_i,\,c_i)$, while the following rule is satisfied: for all pairs of pieces $i$ and $j$, $|r_i-r_j|+|c_i-c_j|\ge|i-j|$. Here $|x|$ means the absolute value of $x$.
     26 
     27 However, Nauuo discovered that sometimes she couldn't find a solution because the chessboard was too small.
     28 
     29 She wants to find the smallest chessboard on which she can put $n$ pieces according to the rules.
     30 
     31 She also wonders how to place the pieces on such a chessboard. Can you help her?
     32 
     33 Input
     34 
     35 The only line contains a single integer $n$ ($1\le n\le 1000$) — the number of chess pieces for the game.
     36 
     37 Output
     38 
     39 The first line contains a single integer — the minimum value of $m$, where $m$ is the length of sides of the suitable chessboard.
     40 
     41 The $i$-th of the next $n$ lines contains two integers $r_i$ and $c_i$ ($1\le r_i,c_i\le m$) — the coordinates of the $i$-th chess piece.
     42 
     43 If there are multiple answers, print any.
     44 
     45 Examples
     46 
     47 Input
     48 
     49 ```
     50 2
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 2
     57 1 1
     58 1 2
     59 ```
     60 
     61 Input
     62 
     63 ```
     64 4
     65 ```
     66 
     67 Output
     68 
     69 ```
     70 3
     71 1 1
     72 1 3
     73 3 1
     74 3 3
     75 ```
     76 
     77 Note
     78 
     79 In the first example, you can't place the two pieces on a $1\times1$ chessboard without breaking the rule. But you can place two pieces on a $2\times2$ chessboard like this:
     80 
     81 ![](https://espresso.codeforces.com/78c10e97bdcfb7f230d9d21244aa034f3e0b967c.png)
     82 
     83 In the second example, you can't place four pieces on a $2\times2$ chessboard without breaking the rule. For example, if you place the pieces like this:
     84 
     85 ![](https://espresso.codeforces.com/609f825ef014d39a4049b9aa721363a480c5fa4a.png)
     86 
     87 then $|r_1-r_3|+|c_1-c_3|=|1-2|+|1-1|=1$, $|1-3|=2$, $1 \lt 2$; and $|r_1-r_4|+|c_1-c_4|=|1-2|+|1-2|=2$, $|1-4|=3$, $2 \lt 3$. It doesn't satisfy the rule.
     88 
     89 However, on a $3\times3$ chessboard, you can place four pieces like this:
     90 
     91 ![](https://espresso.codeforces.com/52a6e19c59ce608c6e87b4e4db09dc54e66a8cca.png)