#P1274. 魔术数字游戏
魔术数字游戏
Description
There are many variations of number-filling grid games. In the grid below, we are to fill the sixteen cells with the numbers through (cells , where , ). To make the game more challenging, we require that the four numbers specified in each of the following items must add up to :
- The four corner cells: .
- Each block at a corner, for example the top-left: .
- The central block: .
- Each row: , where .
- Each column: , where .
- The two diagonals, for example the main diagonal from top-left to bottom-right: .
- From top-right to bottom-left: .
In particular, we will fix the number in a specified cell.
Input Format
The input contains a single line with two positive integers and , indicating that the cell in row and column contains the number . Fill the remaining fifteen cells with the numbers through according to the conditions above.
Output Format
Output all valid solutions in increasing order, separated by a single empty line.
For each valid solution, output four lines, each containing four numbers separated by a single space.
The ordering of valid solutions is determined as follows: compare numbers starting from the first row; within each row, compare from the leftmost number. The solution with the smaller number at the first differing position must be printed first.
1 1
1 4 13 16
14 15 2 3
8 5 12 9
11 10 7 6
1 4 13 16
14 15 2 3
12 9 8 5
7 6 11 10
……剩余214组合法解省略
Hint
For the sample, there are valid fillings.
Constraints: For all test points, it is guaranteed that .
Translated by ChatGPT 5
京公网安备 11011102002149号