#P8642. [蓝桥杯 2016 国 AC] 路径之谜(疑似错题)

[蓝桥杯 2016 国 AC] 路径之谜(疑似错题)

Description

Xiao Ming pretends to be a knight from planet XX and enters a strange castle.

There is nothing in the castle, only a floor paved with square stones.

Assume the castle floor is an n×nn\times n grid, as shown in the figure.

By tradition, the knight must walk from the northwest corner to the southeast corner.

He can move horizontally or vertically, but cannot move diagonally, and cannot jump.

Each time he arrives at a new cell, he shoots one arrow to the due north and one arrow to the due west.

(There are nn targets on the west wall and nn targets on the north wall inside the castle.)

The same cell is allowed to be visited only once. However, he does not have to visit all cells.

If you are only given the number of arrows on the targets, can you deduce the knight’s route?

Sometimes you can, for example, in the case shown in the figure.

The task is: given the numbers on the targets, find the knight’s path (the testdata guarantees the path is unique).

Input Format

The first line contains an integer N(1N10)N(1\leq N\leq 10), meaning the floor has N×NN \times N cells.

The second line contains NN integers separated by spaces, representing the numbers on the targets on the north side (from west to east).

The third line contains NN integers separated by spaces, representing the numbers on the targets on the west side (from north to south).

Output Format

Output one line with several integers, representing the knight’s path.

For convenience, we label each cell with a number, starting from the northwest corner as :0,1,2,3:0,1,2,3 \cdots.

For example, the cells in the figure are numbered as:

0  1  2  3
4  5  6  7
8  9  10 11
12 13 14 15
4
2 4 3 4
4 3 3 3
0 4 5 1 2 3 7 11 10 9 13 14 15

Hint

Time limit: 1 second, 256M. Lanqiao Cup 2016, the 7th National Contest.

Translated by ChatGPT 5