És la solució d'un Sudoku? P16893


Statement
 

pdf   zip

thehtml

Recordeu que un Sudoku és un joc que consisteix a completar una graella 9 × 9 amb números entre 1 i 9 de manera que el resultat final no tingui números repetits a la mateixa fila, columna o submatriu 3 × 3. Per exemple, aquest és un Sudoku i la seva solució:

unit=0.6cm linewidth=0.1pt (9,9) [linewidth=1.25pt](0,0)(0,9) (1,0)(1,9) (2,0)(2,9) [linewidth=1.25pt](3,0)(3,9) (4,0)(4,9) (5,0)(5,9) [linewidth=1.25pt](6,0)(6,9) (7,0)(7,9) (8,0)(8,9) [linewidth=1.25pt](9,0)(9,9)

[linewidth=1.25pt](0,0)(9,0) (0,1)(9,1) (0,2)(9,2) [linewidth=1.25pt](0,3)(9,3) (0,4)(9,4) (0,5)(9,5) [linewidth=1.25pt](0,6)(9,6) (0,7)(9,7) (0,8)(9,8) [linewidth=1.25pt](0,9)(9,9)

[c](0.5,0.5)4 [c](2.5,0.5)5 [c](3.5,0.5)6

[c](1.5,1.5)2 [c](2.5,1.5)9 [c](3.5,1.5)1

[c](4.5,2.5)7 [c](5.5,2.5)5 [c](8.5,2.5)8

[c](2.5,3.5)6 [c](3.5,3.5)4 [c](4.5,3.5)2

[c](1.5,4.5)4 [c](2.5,4.5)8 [c](6.5,4.5)5 [c](7.5,4.5)6

[c](4.5,5.5)6 [c](5.5,5.5)1 [c](6.5,5.5)8

[c](0.5,6.5)1 [c](3.5,6.5)9 [c](4.5,6.5)3

[c](5.5,7.5)6 [c](6.5,7.5)4 [c](7.5,7.5)5

[c](5.5,8.5)2 [c](6.5,8.5)3 [c](8.5,8.5)7

      (9,9) [linewidth=1.25pt](0,0)(0,9) (1,0)(1,9) (2,0)(2,9) [linewidth=1.25pt](3,0)(3,9) (4,0)(4,9) (5,0)(5,9) [linewidth=1.25pt](6,0)(6,9) (7,0)(7,9) (8,0)(8,9) [linewidth=1.25pt](9,0)(9,9)

[linewidth=1.25pt](0,0)(9,0) (0,1)(9,1) (0,2)(9,2) [linewidth=1.25pt](0,3)(9,3) (0,4)(9,4) (0,5)(9,5) [linewidth=1.25pt](0,6)(9,6) (0,7)(9,7) (0,8)(9,8) [linewidth=1.25pt](0,9)(9,9)

[c](0.5,0.5)4 [c](1.5,0.5)7 [c](2.5,0.5)5 [c](3.5,0.5)6 [c](4.5,0.5)8 [c](5.5,0.5)9 [c](6.5,0.5)1 [c](7.5,0.5)3 [c](8.5,0.5)2

[c](0,1) [c](0.5,0.5)9 [c](1.5,0.5)2 [c](2.5,0.5)9 [c](3.5,0.5)1 [c](4.5,0.5)4 [c](5.5,0.5)3 [c](6.5,0.5)6 [c](7.5,0.5)7 [c](8.5,0.5)5

[c](0,2) [c](0.5,0.5)6 [c](1.5,0.5)3 [c](2.5,0.5)1 [c](3.5,0.5)2 [c](4.5,0.5)7 [c](5.5,0.5)5 [c](6.5,0.5)9 [c](7.5,0.5)4 [c](8.5,0.5)8

[c](0,3) [c](0.5,0.5)5 [c](1.5,0.5)1 [c](2.5,0.5)6 [c](3.5,0.5)4 [c](4.5,0.5)2 [c](5.5,0.5)8 [c](6.5,0.5)7 [c](7.5,0.5)9 [c](8.5,0.5)3

[c](0,4) [c](0.5,0.5)2 [c](1.5,0.5)4 [c](2.5,0.5)8 [c](3.5,0.5)3 [c](4.5,0.5)9 [c](5.5,0.5)7 [c](6.5,0.5)5 [c](7.5,0.5)6 [c](8.5,0.5)1

[c](0,5) [c](0.5,0.5)7 [c](1.5,0.5)9 [c](2.5,0.5)3 [c](3.5,0.5)5 [c](4.5,0.5)6 [c](5.5,0.5)1 [c](6.5,0.5)8 [c](7.5,0.5)2 [c](8.5,0.5)4

[c](0,6) [c](0.5,0.5)1 [c](1.5,0.5)5 [c](2.5,0.5)7 [c](3.5,0.5)9 [c](4.5,0.5)3 [c](5.5,0.5)4 [c](6.5,0.5)2 [c](7.5,0.5)8 [c](8.5,0.5)6

[c](0,7) [c](0.5,0.5)3 [c](1.5,0.5)8 [c](2.5,0.5)2 [c](3.5,0.5)7 [c](4.5,0.5)1 [c](5.5,0.5)6 [c](6.5,0.5)4 [c](7.5,0.5)5 [c](8.5,0.5)9

[c](0,8) [c](0.5,0.5)9 [c](1.5,0.5)6 [c](2.5,0.5)4 [c](3.5,0.5)8 [c](4.5,0.5)5 [c](5.5,0.5)2 [c](6.5,0.5)3 [c](7.5,0.5)1 [c](8.5,0.5)7

En aquest problema no us demanem que resolgueu cap Sudoku, només que comproveu que cada matriu donada pot ser la solució d’un Sudoku.

Entrada

L’entrada consisteix en un nombre n, seguit de n casos. Cada cas té 9 files, cadascuna amb 9 ‍números entre 1 i 9.

Sortida

Per a cada cas, escriviu “si” o “no” depenent de si la matriu donada compleix les regles de les solucions dels Sudokus.

Public test cases
  • Input

    2
    
    1 2 3 4 5 6 7 8 9
    4 5 6 7 8 9 1 2 3
    7 8 9 1 2 3 4 5 6
    2 3 1 6 7 4 8 9 5
    8 7 5 9 1 2 3 6 4
    6 9 4 5 3 8 2 1 7
    3 1 7 2 6 5 9 4 8
    5 4 2 8 9 7 6 3 1
    9 6 8 3 4 1 5 7 2
    
    1 2 3 4 5 6 7 8 9
    4 5 6 7 8 9 1 2 3
    7 8 9 1 2 3 4 5 6
    2 3 1 6 7 4 8 9 5
    8 7 5 9 1 2 3 6 4
    6 9 4 5 3 8 2 1 7
    3 1 7 2 6 5 9 4 8
    5 4 2 8 9 7 6 2 1
    9 6 8 3 4 1 5 7 3
    

    Output

    si
    no
    
  • Information
    Author
    Salvador Roura
    Language
    Catalan
    Other languages
    English
    Official solutions
    C++ Python
    User solutions
    C++ Java Python