5096.Quotdoku

Time Limit: 1s Memory Limit: 256MB

Quotdoku is a variant of the game Sudoku. As in Sudoku, the aim is to fill in a 9-by-9 grid with the digits 1 through 9 so that each digit 1 through 9 occurs exactly once in each row, exactly once in each column and exactly once in each of the 9 3-by-3 sub-squares subject to constraints on the choices.

In Sudoku, the constraints are that certain squares must contain fixed values. In Quotdoku, the constraints are on the quotient of some of the adjacent squares within some 3-by-3 sub-squares. In each case, the larger of the two adjacent values is divided by the smaller to obtain the indicated quotient (any remainder is ignored). In the illustration below, the integers in the range 1 through 9 on the separating line indicate the desired quotient.

eXcjDtFHuOhhh5xbuvnbnr44wt6L3I4kvj5NDXT4.png

Write a program to solve Quotdoku problems.

Input Format(From the terminal/stdin)

The first line of input contains a single decimal integer $K, (0 ≤ K ≤ 81)$, which is the number of
pre-specified values.

The next 15 lines of input consist of the values from 0 to 9, separated by spaces. A value of $0$ indicates that there is no constraint for the corresponding pair of values. Otherwise, the input value gives the quotient constraint. Rows $1, 3, 5, 6, 8, 10, 11, 13$ and $15$ contain $6$ values corresponding to constraints on the quotient of dividing values to the left and right of the symbol. Rows $2, 4, 7, 9, 12$ and $14$ contain $9$ values corresponding to constraints on the quotient of dividing values above and below the symbol.

The next $K$ lines of input each consist of three decimal integers in the range $1$ through $9$, each separated by a space. The values give the row, column and value in that order of each pre-specified value.

Output Format(To the terminal/stdout)

Your program should produce $9$ lines of output where each line consists of $9$ decimal digits separated by a single space. The value in the $j$th position in the $i$th line of the 9 output lines is the solution value in column $j$ of row $i$.

Sample Input 1

Copy
0
1 1 0 0 1 2
1 1 1 0 0 0 6 1 2
1 1 0 0 7 3
2 6 1 0 0 0 3 1 2
2 7 0 0 3 1
0 0 1 4 0 0
0 0 0 3 3 2 0 0 0
0 0 1 1 0 0
0 0 0 1 6 1 0 0 0
0 0 7 5 0 0
1 3 0 0 1 1
1 2 2 0 0 0 4 1 6
2 1 0 0 2 4
8 1 1 0 0 0 3 1 9
4 1 0 0 2 3
 \n
 · · · · · \n
 · · · · · · · · \n
 · · · · · \n
 · · · · · · · · \n
 · · · · · \n
 · · · · · \n
 · · · · · · · · \n
 · · · · · \n
 · · · · · · · · \n
 · · · · · \n
 · · · · · \n
 · · · · · · · · \n
 · · · · · \n
 · · · · · · · · \n
 · · · · · \n

Sample Output 1

Copy
3 5 9 2 7 1 6 8 4
4 6 8 5 3 9 1 7 2
2 1 7 4 8 6 3 9 5
5 9 1 3 2 8 4 6 7
7 2 3 9 6 4 5 1 8
6 8 4 7 1 5 9 2 3
9 7 2 1 4 3 8 5 6
8 3 5 6 9 7 2 4 1
1 4 6 8 5 2 7 3 9
 · · · · · · · · \n
 · · · · · · · · \n
 · · · · · · · · \n
 · · · · · · · · \n
 · · · · · · · · \n
 · · · · · · · · \n
 · · · · · · · · \n
 · · · · · · · · \n
 · · · · · · · · \n

Sample Input 2

Copy
3
2 4 0 0 1 1
1 3 9 0 0 0 1 1 1
1 6 0 0 1 3
1 1 3 0 0 0 1 9 1
1 2 0 0 5 2
0 0 1 9 0 0
0 0 0 2 2 5 0 0 0
0 0 1 1 0 0
0 0 0 2 2 1 0 0 0
0 0 3 4 0 0
4 1 0 0 4 1
2 1 1 0 0 0 4 2 1
1 2 0 0 2 1
4 2 1 0 0 0 9 1 1
1 1 0 0 3 1
1 6 7
6 9 9
4 3 7
 \n
 · · · · · \n
 · · · · · · · · \n
 · · · · · \n
 · · · · · · · · \n
 · · · · · \n
 · · · · · \n
 · · · · · · · · \n
 · · · · · \n
 · · · · · · · · \n
 · · · · · \n
 · · · · · \n
 · · · · · · · · \n
 · · · · · \n
 · · · · · · · · \n
 · · · · · \n
 · · \n
 · · \n
 · · \n

Sample Output 2

Copy
5 2 9 1 3 7 8 6 4
4 6 1 8 5 2 7 9 3
7 8 3 4 6 9 5 1 2
3 5 7 6 9 1 4 2 8
8 9 2 3 4 5 6 7 1
6 1 4 7 2 8 3 5 9
1 4 5 9 7 3 2 8 6
2 3 8 5 1 6 9 4 7
9 7 6 2 8 4 1 3 5
 · · · · · · · · \n
 · · · · · · · · \n
 · · · · · · · · \n
 · · · · · · · · \n
 · · · · · · · · \n
 · · · · · · · · \n
 · · · · · · · · \n
 · · · · · · · · \n
 · · · · · · · · \n
Source: 2022 Great NY Regional

Submit

请先 登录

© 2025 FAQs