Hdu1426 Sudoku killer Deep Search

Source: Internet
Author: User
# Include <stdio. h> int map [9] [9], Kong [90] [2], kN; int CI = 0, F; int he (int I, Int J, int K) // judge whether K can be entered. The value cannot be {int o, p, Oo, pp; For (O = 0; O <9; O ++) if (Map [I] [O] = k) return 0; For (O = 0; O <9; O ++) if (Map [O] [J] = k) return 0; oo = I/3*3; pp = J/3*3; for (O = Oo; O <(OO + 3); O ++) for (P = pp; P <(PP + 3); P ++) if (Map [O] [p] = k) return 0; return 1;} void Shu () // output {int I, j; F = 1; if (CI! = 1) printf ("\ n"); for (I = 0; I <9; I ++) {printf ("% d ", map [I] [0]); For (j = 1; j <9; j ++) printf ("% d", map [I] [J]); printf ("\ n") ;}} void DFS (int l) {int K; If (L <kN) {for (k = 1; k <10; k ++) // in turn, try Kong [l] and the assigned value {If (HE (Kong [l] [0], Kong [l] [1], k )) {map [Kong [l] [0] [Kong [l] [1] = K; DFS (L + 1); If (f) return; map [Kong [l] [0] [Kong [l] [1] = 0 ;}} elseshu () ;}int main () {char C; int I, j; while (1) {kN = 0; for (I = 0; I <9; I ++) for (j = 0; j <9; j ++) {scanf ("% C", & C); If (C = '? ') {Map [I] [J] = 0; Kong [kN] [0] = I; // set it? Records the coordinates in Kong [] so that the values of Kong [kN] [1] = J; kN ++;} are assigned in sequence ;} else map [I] [J] = C-'0'; getchar () ;}ci ++; F = 0; DFS (0 ); // value I = scanf ("% C", & C); if (I =-1) from Kong [0] // if the character cannot be read, jump out of break;} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.