I was wrong about this question, so I thought the numbers in the columns would be totally different.
Debugging took me a long time to clean
In fact, as long as the difference in the small square is enough
Note thatTips:
Vis1 [I] [ans [I] [J] = 1; vis2 [ans [I] [J] [J] = 1;
So that the rows and columns have different numbers for weight determination.
# Include <stdio. h> # include <string. h> int map [10] [10], ar [80] [2], used1 [10] [10], used2 [10] [10]; int judge (Int J, int K, int I) // Palace, J/3*3 very clever Ah {int p, q; For (P = J/3*3; P <= J/3*3 + 2; p ++) {for (q = K/3*3; q <= K/3*3 + 2; Q ++) {If (Map [p] [Q] = I) return 0 ;}} return 1 ;}int DFS (INT num) // Number of 0 {int I, j, k; j = ar [num] [0], K = ar [num] [1]; If (Num <0) return 1; for (I = 0; I <9; I ++) // enter the number {If (Judge (j, k, I + 1 )&&! Used1 [J] [I] &! Used2 [k] [I]) // If are you familiar with this? {Used1 [J] [I] = used2 [k] [I] = 1; Map [J] [k] = I + 1; if (DFS (num-1 )) return 1; used1 [J] [I] = used2 [k] [I] = 0; Map [J] [k] = 0 ;}} return 0 ;} int main () {int I, j, T, num; char STR [10]; scanf ("% d", & T); While (t --) {memset (used1, 0, sizeof (used1); memset (used2, 0, sizeof (used2); num = 0; for (I = 0; I <9; I ++) {scanf ("% s", STR); For (j = 0; j <9; j ++) {map [I] [J] = STR [J]-'0'; If (! Map [I] [J]) // record 0 position {ar [num] [0] = I; Ar [num] [1] = J; num ++ ;} if (Map [I] [J]) used1 [I] [map [I] [J]-1] = 1; // record the number of rows I }}for (j = 0; j <9; j ++) {for (I = 0; I <9; I ++) {If (Map [I] [J]) used2 [J] [map [I] [J]-1] = 1; // record the number of column J} DFS (num-1); for (I = 0; I <9; I ++) {for (j = 0; j <9; j ++) printf ("% d", map [I] [J]); printf ("\ n") ;}} return 0 ;}