Poj 2676 Sudoku

Source: Internet
Author: User

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 ;}


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.