1968E.md (2352B)
1 Source: https://codeforces.com/problemset/problem/1968/E 2 3 E. Cells Arrangement 4 5 time limit per test 6 7 2 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 You are given an integer $n$. You choose $n$ cells $(x_1,y_1), (x_2,y_2),\dots,(x_n,y_n)$ in the grid $n\times n$ where $1\le x_i\le n$ and $1\le y_i\le n$. 22 23 Let $\mathcal{H}$ be the set of distinct Manhattan distances between any pair of cells. Your task is to maximize the size of $\mathcal{H}$. Examples of sets and their construction are given in the notes. 24 25 If there exists more than one solution, you are allowed to output any. 26 27 Manhattan distance between cells $(x_1,y_1)$ and $(x_2,y_2)$ equals $|x_1-x_2|+|y_1-y_2|$. 28 29 Input 30 31 The first line contains a single integer $t$ ($1\le t\le 50$) — the number of test cases. 32 33 Each of the following $t$ lines contains a single integer $n$ ($2\le n\le 10^3$). 34 35 Output 36 37 For each test case, output $n$ points which maximize the size of $\mathcal{H}$. It is not necessary to output an empty line at the end of the answer for each test case. 38 39 Example 40 41 Input 42 43 ``` 44 5 45 46 2 47 48 3 49 50 4 51 52 5 53 54 6 55 ``` 56 57 Output 58 59 ``` 60 1 1 61 1 2 62 63 2 1 64 2 3 65 3 1 66 67 1 1 68 1 3 69 4 3 70 4 4 71 72 1 1 73 1 3 74 1 4 75 2 1 76 5 5 77 78 1 4 79 1 5 80 1 6 81 5 2 82 5 5 83 6 1 84 ``` 85 86 Note 87 88 In the first testcase we have $n=2$. One of the possible arrangements is: 89 90  The arrangement with cells located in $(1,1)$ and $(1,2)$. In this case $\mathcal{H}=\{|1-1|+|1-1|,|1-1|+|2-2|,|1-1|+|1-2|\}=\{0,0,1\}=\{0,1\}$. Hence, the size of $\mathcal{H}$ is $2$. It can be shown that it is the greatest possible answer. 91 92 In the second testcase we have $n=3$. The optimal arrangement is: 93 94  The arrangement with cells located in $(2,1)$, $(2,3)$ and $(3,1)$. 95 96 $\mathcal{H}$=$\{|2-2|+|1-1|,|2-2|+|3-3|,|3-3|+|1-1|,|2-2|+|1-3|,|2-3|+|1-1|,|2-3|+|3-1|\}$=$\{0,0,0,2,1,3\}$=$\{0,1,2,3\}$. 97 98 For $n=4$ a possible arrangement is: 99 100  101 102 For $n=5$ a possible arrangement is: 103 104  105 106 For $n=6$ a possible arrangement is: 107 108 