#P13054. [GCJ 2020 #1A] Pascal Walk
[GCJ 2020 #1A] Pascal Walk
题目描述
Pascal's triangle consists of an infinite number of rows of an increasing number of integers each, arranged in a triangular shape.
Let us define as the -th position from the left in the -th row, with both and counted starting from 1. Then Pascal's triangle is defined by the following rules:
- The -th row contains positions .
- The numbers at positions and are 1 , for all .
- The number at position is the sum of the numbers at positions and , for all with .
The first 5 rows of Pascal's triangle look like this:
In this problem, a Pascal walk is a sequence of positions $\left(\mathrm{r}_{1}, \mathrm{k}_{1}\right),\left(\mathrm{r}_{2}, \mathrm{k}_{2}\right), \ldots,\left(\mathrm{r}_{\mathrm{s}}, \mathrm{k}_{\mathrm{s}}\right)$ in Pascal's triangle that satisfy the following criteria:
- and .
- Each subsequent position must be within the triangle and adjacent (in one of the six possible directions) to the previous position. That is, for all $\mathrm{i} \geqslant 1,\left(\mathrm{r}_{\mathrm{i}+1}, \mathrm{k}_{\mathrm{i}+1}\right)$ must be one of the following that is within the triangle: $\left(\mathrm{r}_{\mathrm{i}}-1, \mathrm{k}_{\mathrm{i}}-1\right),\left(\mathrm{r}_{\mathrm{i}}-1, \mathrm{k}_{\mathrm{i}}\right),\left(\mathrm{r}_{\mathrm{i}}, \mathrm{k}_{\mathrm{i}}-1\right),\left(\mathrm{r}_{\mathrm{i}}, \mathrm{k}_{\mathrm{i}}+1\right),\left(\mathrm{r}_{\mathrm{i}}+1, \mathrm{k}_{\mathrm{i}}\right),\left(\mathrm{r}_{\mathrm{i}}+1, \mathrm{k}_{\mathrm{i}}+1\right)$.
- No position may be repeated within the sequence. That is, for every , either $\mathrm{r}_{\mathrm{i}} \neq \mathrm{r}_{\mathrm{j}}$ or $\mathrm{k}_{\mathrm{i}} \neq \mathrm{k}_{\mathrm{j}}$, or both.
Find any Pascal walk of positions such that the sum of the numbers in all of the positions it visits is equal to . It is guaranteed that at least one such walk exists for every .
输入格式
The first line of the input gives the number of test cases, . test cases follow. Each consists of a single line containing a single integer .
输出格式
For each test case, first output a line containing case #x:, where is the test case number (starting from 1). Then, output your proposed Pascal walk of length using additional lines. The -th of these lines must be where $\left(\mathrm{r}_{\mathrm{i}}, \mathrm{k}_{\mathrm{i}}\right)$ is the -th position in the walk. For example, the first line should be since the first position for all valid walks is . The sum of the numbers at the positions of your proposed Pascal walk must be exactly .
3
1
4
19
Case #1:
1 1
Case #2:
1 1
2 1
2 2
3 3
Case #3:
1 1
2 2
3 2
4 3
5 3
5 2
4 1
3 1
提示
Sample Explanation
In Sample Case #1, only the starting position is needed.
In Sample Case #2, notice that although a shorter path exists, the path does not need to be of minimal length, as long as it uses no more than 500 positions.
The following image depicts our solution to Sample Case #3:
Limits
- .
Test set 1 (3 Pts, Visible Verdict)
- .
Test set 2 (11 Pts, Visible Verdict)
- .
Test set 3 (21 Pts, Hidden Verdict)
- .