logo AlgoBeat OnlineJudge
登录 注册

#213180. [GCJ 2020 #1A] Pascal Walk

内存限制:1024 MiB 时间限制:20000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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 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 must be one of the following that is within the triangle: .
  • No position may be repeated within the sequence. That is, for every , either or , 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 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 .

样例

样例输入 1

3
1
4
19

样例输出 1

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)

  • .